Quantcast

Disabling widgets [especially ttk.Scale]

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Disabling widgets [especially ttk.Scale]

Martin B.-4
hi all,
i have a little problem with setting state of ttk.Scale widget.

i have a ttk.Checkbutton which operates with ttk.Scale. [enabling,disabling]

<code>

self.check=BooleanVar()
button = ttk.Checkbutton(self, text='',variable=self.var,command=self._setActive)
self.slider = ttk.Scale(self)

def _setActive(self, event=None):
        if self.check.get():
                self.slider.state(statespec=('active',))
        else:
                self.slider.state(statespec=('disabled',))

</code>

but if i make checkbutton active, slider is disabled :(
how i make Scale state enabled and disabled if
self.slider.config(state=NORMAL) is unknown option.

sry for newbie Q.
thanks
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Disabling widgets [especially ttk.Scale]

Michael Lange
Hi,

Thus spoketh "Martin B." <[hidden email]>
unto us on Mon, 17 Jan 2011 17:36:52 +0100:

(...)
>
> but if i make checkbutton active, slider is disabled :(
> how i make Scale state enabled and disabled if
> self.slider.config(state=NORMAL) is unknown option.

if you're familiar with Tkinter states, the handling of states in ttk may
seem a bit odd. To set a widget to "normal" state you must not
define the state "normal" but instead turn off the "disabled" state by
prefixing the state name with an exclamation mark. Here's a minimal
example how this can be done:

#############################################################
import Tkinter
import ttk
root = Tkinter.Tk()
s = ttk.Scale(root)
s.pack(side='right', fill='x')

var = Tkinter.StringVar()
var.set('!disabled')

def callback():
    s.state((var.get(),))

button = ttk.Checkbutton(root, text='foo', variable=var,
           onvalue='disabled', offvalue='!disabled', command=callback)
button.pack(side='left', padx=40, pady=100)
root.mainloop()
#############################################################


I hope this helps

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

        "What terrible way to die."
        "There are no good ways."
                -- Sulu and Kirk, "That Which Survives", stardate unknown
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Disabling widgets [especially ttk.Scale]

Martin B.-4
In reply to this post by Martin B.-4
V Mon, 17 Jan 2011 17:36:52 +0100
"Martin B." <[hidden email]> napsáno:

eh i have solution.
must be    state(statespec=('active', '!disabled')

sry


> hi all,
> i have a little problem with setting state of ttk.Scale widget.
>
> i have a ttk.Checkbutton which operates with ttk.Scale.
> [enabling,disabling]
>
> <code>
>
> self.check=BooleanVar()
> button = ttk.Checkbutton(self,
> text='',variable=self.var,command=self._setActive) self.slider =
> ttk.Scale(self)
>
> def _setActive(self, event=None):
> if self.check.get():
> self.slider.state(statespec=('active',))
> else:
> self.slider.state(statespec=('disabled',))
>
> </code>
>
> but if i make checkbutton active, slider is disabled :(
> how i make Scale state enabled and disabled if
> self.slider.config(state=NORMAL) is unknown option.
>
> sry for newbie Q.
> thanks
> _______________________________________________
> Tkinter-discuss mailing list
> [hidden email]
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>

_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Disabling widgets [especially ttk.Scale]

Martin B.-4
In reply to this post by Michael Lange
V Mon, 17 Jan 2011 19:08:56 +0100
Michael Lange <[hidden email]> napsáno:

Thanks for your example, seems to be better solution that mine :)
I think that ttk.Checkbutton variable must be BooleanVar().
now i know that not.
thanks


> Hi,
>
> Thus spoketh "Martin B." <[hidden email]>
> unto us on Mon, 17 Jan 2011 17:36:52 +0100:
>
> (...)
> >
> > but if i make checkbutton active, slider is disabled :(
> > how i make Scale state enabled and disabled if
> > self.slider.config(state=NORMAL) is unknown option.
>
> if you're familiar with Tkinter states, the handling of states in ttk
> may seem a bit odd. To set a widget to "normal" state you must not
> define the state "normal" but instead turn off the "disabled" state by
> prefixing the state name with an exclamation mark. Here's a minimal
> example how this can be done:
>
> #############################################################
> import Tkinter
> import ttk
> root = Tkinter.Tk()
> s = ttk.Scale(root)
> s.pack(side='right', fill='x')
>
> var = Tkinter.StringVar()
> var.set('!disabled')
>
> def callback():
>     s.state((var.get(),))
>
> button = ttk.Checkbutton(root, text='foo', variable=var,
>            onvalue='disabled', offvalue='!disabled', command=callback)
> button.pack(side='left', padx=40, pady=100)
> root.mainloop()
> #############################################################
>
>
> I hope this helps
>
> Michael
>
>
> .-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-.
> --- ... .--. . .-.
>
> "What terrible way to die."
> "There are no good ways."
> -- Sulu and Kirk, "That Which Survives", stardate
> unknown _______________________________________________
> Tkinter-discuss mailing list
> [hidden email]
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>

_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Loading...