【发布时间】:2021-03-08 11:49:53
【问题描述】:
我有一个运行良好的代码,但它没有给我透明背景,(这里是图片)经过网络研究,我找到了使用画布小部件的解决方案,我们可以使用透明背景的图片.
这是我的代码,
import tkinter as tk
from PIL import Image, ImageTk
def work(progress=1):
if progress > 300: # define the width by yourself
return
tmp_images = ImageTk.PhotoImage(progress_images.resize((progress, 10))) # the image size
lb.image = tmp_images # keep reference
lb["image"] = tmp_images # change the image
root.add = root.after(100, work, progress+10) # define the amplitude by yourself
root = tk.Tk()
progress_images = Image.open("path.png")
lb = tk.Label(root, bg="black")
lb.pack(side="left")
work()
root.mainloop()
但我很困惑如何将 Label 小部件更改为 Canvas ?谁能帮帮我?我还是 Tkinter 的菜鸟!!!
【问题讨论】:
标签: python python-3.x user-interface tkinter tkinter-canvas