我有代碼,它會很高興地刪除按鈕後,它將被按下,或將運行代碼,但我不能使它們都做。我想知道是否有這樣做。在python tkinter中,我想做一個按鈕disapear,並運行一個定義
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
你是什麼意思「做這兩個」?如果要刪除按鈕並執行其他代碼,請將所有代碼封裝在函數中,並在按下按鈕時調用它。 –
試圖把它放到一個功能之前,但它似乎並沒有工作 – notme21