I want to change ttk.Button's state according to some internal logic. I create a button and associate a style with it:
cardBtnStyle = ttk.Style()
cardBtnStyle.configure('CB.TButton')
cardBtn = ttk.Button(top, text="Make SD card", style='CB.TButton', command = cardCreateCallBack).grid(column=1, row=5)
Following statement has no effect:
style.configure('CB.TButton', state='disabled')
But when I create a button like this, it is disabled:
cardBtn = ttk.Button(top, text="Make SD card", style='CB.TButton', state='disabled', command = cardCreateCallBack).grid(column=1, row=5)
How do I change ttk.Button state in Python?
OS: Ubuntu 13.10
Python: 2.7.5+
Build A Paint Program With TKinter and Python Tkinter Button widgets can be enabled and disabled by defining its state in the Button Object. The state attribute generally accepts two values Normal and Disabled which are used for enabling and disabling the button, respectively.
Tkinter widgets are used to add Buttons, Labels, Text, ScrollBar, etc., however, tkinter. ttk supports a variety of widgets as compared to tkinter widgets. Tkinter. ttk doesn't support Place, Pack() and Grid(), thus it is recommended to use tkinter widget with ttk.
The button state is not part of its style. You can use the state() method to modify it:
cardBtn.state(["disabled"]) # Disable the button.
cardBtn.state(["!disabled"]) # Enable the button.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With