1

I'm trying to reenable my Scale widget in Python tkinter after disabling it but it doesn't work. I tried multiple options but none are working.

s.state(["normal"]);
s.configure(state='normal');

The error that I'm getting is saying:

_tkinter.TclError: unknown option "-state"
finefoot
  • 9,914
  • 7
  • 59
  • 102
Zitrone
  • 79
  • 8
  • Are you using a `tkinter.Scale` or a `ttk.Scale`? – j_4321 Dec 12 '17 at 08:34
  • Im using `ttk.Scale`. – Zitrone Dec 12 '17 at 08:38
  • I think that you should rephrase your question a little to `How to enable/disable ttk widget`, since solution applies to all of them. I found nearly a [duplicate](https://stackoverflow.com/questions/21673257/python-ttk-disable-enable-a-button) of your question, because someone was curious only about a button. – CommonSense Dec 12 '17 at 09:07
  • 1
    Okay, I just changed it. – Zitrone Dec 12 '17 at 19:25

1 Answers1

2

Since you use ttk widget, the state that you needed to reenable your widget is !disabled.

According to ttk states:

A state specification or stateSpec is a list of state names, optionally prefixed with an exclamation point (!) indicating that the bit is off.

try:
    import tkinter as tk
    import tkinter.ttk as ttk
except ImportError:
    import Tkinter as tk
    import ttk


root = tk.Tk()

scale = ttk.Scale(root)
scale.pack()

#   disable scale
scale.state(['disabled'])
#   enable scale
scale.state(['!disabled'])

root.mainloop()
CommonSense
  • 4,232
  • 2
  • 14
  • 38
  • Note that ttk and tkinter use a different set of states/state names. tkinter uses 'normal' is the default; 'disabled', or 'disable' makes it visible but not responsive/greyed out; and 'active' for the state seen when mouse hovers over... e.g., button turns blue with mac aqua theme. – fitzl Dec 24 '18 at 09:06