Python 如何在tkinter GUI中使用动画使图像宽度变长?
我有这个图像,我想让这个图像的宽度更长,直到使用动画的tkinter窗口结束,但我没有任何适当的方法来完成这个任务。有什么建议吗?使用Python 如何在tkinter GUI中使用动画使图像宽度变长?,python,python-3.x,user-interface,tkinter,tkinter-canvas,Python,Python 3.x,User Interface,Tkinter,Tkinter Canvas,我有这个图像,我想让这个图像的宽度更长,直到使用动画的tkinter窗口结束,但我没有任何适当的方法来完成这个任务。有什么建议吗?使用PIL的解决方案: 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.
PIL的解决方案
:
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()
动画:
是否使用动画使图像变宽?什么意思?是的。因此,它看起来像一个轮询效果。有
Progressbar
和tkinter
是,但是可以设置图像宽度的动画吗?因为我希望通过动画增加宽度。谢谢你的解决方案!!!!是否可以使用画布删除背景色并使其透明?@sodmzs“删除背景色”是可能的,但我不知道如何使其透明。