tkinter 改變按鈕狀態


import tkinter as tk


def btn1_change_btn1(event):
    '''方式一:通過事件控制自己'''
    if event.widget['state'] == 'normal':
        event.widget['state'] = 'disabled'
    elif event.widget['state'] == 'disabled':
        #event.widget['state'] = 'normal'
        pass

def btn2_change_btn1():
    '''方式二:直接點名,控制別的按鈕'''
    if btn1['state'] == 'normal':
        btn1['state'] = 'disabled'
    elif btn1['state'] == 'disabled':
        btn1['state'] = 'normal'
    
root = tk.Tk()

btn1 = tk.Button(root, text='REOOT', fg="blue", state=tk.DISABLED, width=12, height=1)
btn1.pack()
btn2 = tk.Button(root, text='TEST', fg="blue", state='normal', width=12, height=1, command=btn2_change_btn1)
btn2.pack()

btn1.bind('<Button-1>', btn1_change_btn1)

root.mainloop()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM