[爆卦]Tkinter label是什麼?優點缺點精華區懶人包

為什麼這篇Tkinter label鄉民發文收入到精華區:因為在Tkinter label這個討論話題中,有許多相關的文章在討論,這篇最有參考價值!作者caesar0929 (一生懸命)看板Python標題[問題] Tk 按一個鈕 換一張圖的方法?...


打擾了

想請問一下下面的語法

我寫的時候是希望一開始有old.png

但按一下鈕以後 本來old.png的那一個位置會出現new.png

但是我發現如果我把msgbox關掉的時候 new.png就會不見

如果我把msgbox那段註解掉 按完鈕也是本來的old.png消失之後那邊一片空白 沒辦法看到new.png

想請問有辦法改進嗎?

目前因為一些特別的原因 希望是在tk這個GUI下做這件事

先謝謝各位


from Tkinter import *
from PIL import Image, ImageTk

root = Tk()
root.geometry('300x300')

def on_click():
img1 = ImageTk.PhotoImage(file='new.png')
La.configure(image = img1)
La.update_idletasks()
import tkMessageBox
tkMessageBox.showinfo(title="Stop", message="I wanna change the
image!")

img = ImageTk.PhotoImage(file='old.png')
La = Label(root, text="abc", image=img)
La.pack(side="top")

Butt = Button(root,text= "Change Image", command = on_click)
Butt.pack()

root.mainloop()

--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.177.203.198
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1513685387.A.718.html
Ruination: 把img1宣告為global變數即可 12/20 15:19
caesar0929: 謝謝感謝樓上 可以了:D 12/21 21:44

你可能也想看看

搜尋相關網站