[Tkinter-discuss] Disabling widgets [especially ttk.Scale]

Martin B. spooky.ln at tbs-software.com
Mon Jan 17 19:14:53 CET 2011


V Mon, 17 Jan 2011 19:08:56 +0100
Michael Lange <klappnase at web.de> 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." <spooky.ln at tbs-software.com> 
> 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
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
> 



More information about the Tkinter-discuss mailing list