我有代码,将高兴地删除按钮后,按下它,或将运行代码,但我不能让它做这两个。我想知道是否有什么办法来做这件事。你知道吗
import tkinter
window = tkinter.Tk()
def start():
gamestart = True
#this runs the code at the end
#btn = tkinter.Button(window, text = 'Prepare to fight' , command = start)
#this would create a button that runs the code(but not perfectly)
btn = tkinter.Button(window, text="Prepare to Fight", command=lambda: btn.pack_forget())
#this creates a button that dissapears
btn.pack()
#creates button
window.mainloop()
if gamestart == True:
lbl = tkinter.Label(window, text = 'WELCOME TO PYTHON COMBAT')
#beggining of game
如果您只想使用
command
来执行definition
,同时删除button
,那么您只需要调用command
,它删除button
,并执行您需要的任何代码段。你知道吗这只需要正确使用
lambda
就可以将包含button
的变量传递给definition
,如下所示:上面的只会“隐藏”这个
button
意思是你可以pack
以后再这样做,下面的会完全删除button
:相关问题 更多 >
编程相关推荐