import tkinter as tk
def rand1():
global rand_called
rand_called += 1
rand_called = 0
games_number = int(input('How many games would you like to play? '))
m_gui = tk.Tk()
button1 = tk.Button(m_gui, text = 'Door 1', fg = 'green', bg = 'red', command = rand1)
button1.place(x = 20,y = 30)
我希望在m_gui
推送button1
次之后销毁games_number
窗口。
我试过这个:
while True:
if rand_called > games_number:
m_gui.destroy()
break
m_gui.mainloop()
但它无法完成这项工作。
请帮帮我
答案 0 :(得分:2)
您需要将逻辑放在rand1
。
def rand1():
global rand_called
rand_called += 1
if rand_called > games_number:
m_gui.destroy()