Pergunta

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+

Foi útil?

Solução

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.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top