from tkinter import *
from time import sleep
root = Tk()
l = Label ( root , text = "bla" )
b = Button ( root , text = "python je glup" )
def glupsam ():
b.grid_forget()
b.update_idletasks()
l.grid ( row = 0 , column = 0 )
l.update_idletasks()
sleep ( 2 )
l.grid_forget()
l.update_idletasks()
b.grid(row = 0 , column = 0)
b.grid( row = 0 , column = 0 )
b.configure ( command = glupsam )
root.mainloop()
我是python和tkinter的新手。 为什么这个代码每按一次按钮就不会在网格(0,0)上切换标签和按钮,但只是第一次
答案 0 :(得分:0)
尝试使用after
恢复按钮,而不是使用sleep
。
from tkinter import *
from time import sleep
root = Tk()
l = Label ( root , text = "bla" )
b = Button ( root , text = "python je glup" )
def glupsam ():
b.grid_forget()
b.update_idletasks()
l.grid ( row = 0 , column = 0 )
l.update_idletasks()
def f():
l.grid_forget()
l.update_idletasks()
b.grid(row = 0 , column = 0)
root.after(2000, f)
b.grid( row = 0 , column = 0 )
b.configure ( command = glupsam )
root.mainloop()