如何將 Tkinter 按鈕狀態從停用更改為正常?
Tkinter 提供 Button 小部件以建立觸發事件的按鈕。假設我們建立了一個已經在應用程式中停用的按鈕。為了更改按鈕的狀態,我們可以使用 state 屬性。
state 屬性用於在應用程式中啟用和停用按鈕。為了更改應用程式的狀態,我們可以執行兩個操作:state=DISABLED 和 state=NORMAL。
示例
#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("650x450") #Define a function for Button Object def quit_win(): win.destroy() #Create a button to quit the window Button(win,text="Quit", command=quit_win, font=('Helvetica bold',20), state= NORMAL).pack(pady=5) win.mainloop()
輸出 1
按鈕被停用時的輸出:
輸出 2
當 Button state=NORMAL 時的輸出:
廣告