簡體   English   中英

如何在 tkinter GUI 中使用動畫使圖像的寬度更長?

[英]how to make the width of image longer using animation in tkinter GUI?

我有這張圖片圖片 我想使用動畫將這個圖像的寬度延長到 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.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()

動畫片:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM