简体   繁体   中英

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

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" 

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM