0
我編寫的這段代碼應該每次點擊一個按鈕時都會添加一張圖片,但是當我做了不止一次後,最後一張圖片消失了。Tkinter標籤圖像變爲空白
import tkinter
suits = ["club", "heart", "diamond", "spade"]
faces = ["jack", "queen", "king"]
def deal():
global value
global card
global deck
value, card = deck.pop(0)
print(deck)
return card
def image():
global count
tkinter.Label(root, image=deal()).grid(row=1, column=count)
count += 1
root = tkinter.Tk()
deck = []
for x in range(1, 11):
for y in suits:
pic = "cards/{}_{}.png".format(x, y)
img = tkinter.PhotoImage(file=pic)
deck.append((x, img))
for z in faces:
pic = "cards/{}_{}.png".format(z, y)
img = tkinter.PhotoImage(file=pic)
deck.append((10, img))
value, card = deck.pop(0)
count = 0
tkinter.Button(root, text="Click me", command=image).grid(row=0, column=0)
root.mainloop()
我該如何解決這個問題?