简体   繁体   English

禁用后如何(重新)启用tkinter ttk Scale小部件?

[英]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. 我试图在禁用它之后在Python tkinter中重新启用Scale小部件,但它不起作用。 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 . 由于您使用的是ttk小部件,因此重新启用小部件所需的状态为!disabled

According to ttk states : 根据ttk状态

A state specification or stateSpec is a list of state names, optionally prefixed with an exclamation point (!) indicating that the bit is off. 状态规范或stateSpec是状态名称的列表,可以选择在其前面加上感叹号(!),以指示该位已关闭。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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