单击其中的按钮几次后,如何销毁 window(使用 tkinter)?
How can I destroy a window (using tkinter) after a button in it was clicked several times?
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
window 在 button1
被推送 games_number
次后销毁。
我试过这个:
while True:
if rand_called > games_number:
m_gui.destroy()
break
m_gui.mainloop()
但这行不通。
请帮帮我
你需要把逻辑放在rand1
。
def rand1():
global rand_called
rand_called += 1
if rand_called > games_number:
m_gui.destroy()
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
window 在 button1
被推送 games_number
次后销毁。
我试过这个:
while True:
if rand_called > games_number:
m_gui.destroy()
break
m_gui.mainloop()
但这行不通。
请帮帮我
你需要把逻辑放在rand1
。
def rand1():
global rand_called
rand_called += 1
if rand_called > games_number:
m_gui.destroy()