图像包裹在枕头中

问题描述 投票:0回答:1

有没有办法让一个图像不遮挡其后面的另一个图像?

我已附上 2 张代码图像,其中一张已加载图像,另一张图像已加载。

将多个图像加载到 customtkinter 应用程序时,我遇到了一个特定问题。这个问题我觉得很简单,但却一直让我抓狂。我可以很好地加载图像,但是当您引入另一张图像时,它似乎占据了整个图像。即使图像是透明的,它仍然设法阻挡其后面的图像。

import customtkinter as ctk
from PIL import Image, ImageTk

app = ctk.CTk()
app.configure(bg="#222")
app.geometry("600x600")

grid = Image.open("grid.png")
grid_image = ImageTk.PhotoImage(grid)
grid_label = ctk.CTkLabel(app, image=grid_image, text='')
grid_label.place(x=25, y=25)

line = Image.open("line.png").rotate(45, expand=1)
line_image = ImageTk.PhotoImage(line)
line_label = ctk.CTkLabel(app, image=line_image, text='')
line_label.place(x=10, y=10)

app.mainloop()

仅当将图像放置在现有图像上时才会出现此问题。这是我能将这个问题简化到的最好的结果。

1 image Both images

我尝试过 .convert('RGBA') 函数, 我尝试过 .rotate(45, fillcolor=tuple(np.mean(np.array(line_i)[0,:], axis=0).astype(int))) 我尝试过ImageChops

还有人解决这个问题吗?

python tkinter python-imaging-library customtkinter
1个回答
0
投票

有没有办法让一个图像不遮挡其后面的另一个图像?

问题可以解决。

  • 第一张图片,你有
    y=25
  • 你的第二张图片
    y=10
  • 设置
    y = 350
    而不是
    y=10

片段:

import customtkinter as ctk
from PIL import Image, ImageTk

app = ctk.CTk()
app.configure(bg="#222")
app.geometry("600x600")

grid = Image.open("p2.png")
grid_image = ImageTk.PhotoImage(grid)
grid_label = ctk.CTkLabel(app, image=grid_image, text='')
grid_label.place(x=25, y=25)

line = Image.open("p11.png").rotate(45, expand=1)
line_image = ImageTk.PhotoImage(line)
line_label = ctk.CTkLabel(app, image=line_image, text='')
line_label.place(x=25, y=350)

app.mainloop()

截图:

© www.soinside.com 2019 - 2024. All rights reserved.