如何在 tkinter GUI 中使用动画使图像的宽度更长? [英] how to make the width of image longer using animation in tkinter GUI?
本文介绍了如何在 tkinter GUI 中使用动画使图像的宽度更长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这张图片 并且我想使用动画将此图像的宽度延长到 tkinter 窗口的末尾,但我没有任何适当的方法来实现这一点任务.有什么建议吗?
I have this image and I want to make the width of this image longer till the end of the window of tkinter using animation but I haven't got any proper way to achieving this task. any suggestions ?
推荐答案
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()
动画:
这篇关于如何在 tkinter GUI 中使用动画使图像的宽度更长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文