How to (re)enable tkinter ttk Scale widget after it has been disabled?

1.5k Views Asked by At

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"
1

There are 1 best solutions below

1
On BEST ANSWER

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()