Disabling tkinter ttk scale widget

后端 未结 2 1582
遥遥无期
遥遥无期 2020-12-12 01:20

I am trying to disable all of the (ttk) widgets in a frame, but it appears that the scale widget is giving me some trouble, as it throws the following exception:

相关标签:
2条回答
  • 2020-12-12 01:32

    For ttk widgets you use the state method. The state method for buttons and entry widgets are just a convenience function to mimic the standard button and entry widgets.

    You can rewrite your function like this:

    def disable_widgets(parent):
        for child in parent.winfo_children():
            child.state(["disabled"])
    

    ttk states are mentioned in the ttk documentation here (though the description borders on useless): https://docs.python.org/3.1/library/tkinter.ttk.html#widget-states

    0 讨论(0)
  • 2020-12-12 01:55

    another way:

    scale_to_disable.configure(state='disabled')  # 'normal'
    

    You can consider that set the breakpoint at the configure of the class Scale (from tkinter.ttk import Scale) may get some helpful.

    The following is part of the code to intercept the class Scale

    class Scale(Widget, tkinter.Scale):
    
        ...
    
        def configure(self, cnf=None, **kw):
            if cnf:
                kw.update(cnf)
            Widget.configure(self, **kw)
    
    0 讨论(0)
提交回复
热议问题