[Tkinter-discuss] Lazy updating of image data in ttk widgets

Bob Greschke bob at passcal.nmt.edu
Fri Mar 8 19:12:50 CET 2013


>On 2013-03-08, at 11:02, Michael Lange <klappnase at web.de> wrote:

> On Fri, 8 Mar 2013 10:24:33 -0700
> Bob Greschke <bob at passcal.nmt.edu> wrote:
> 
>> Happens on
>> 
>> Python 2.7.2 (default, Jul 18 2011, 14:33:20) 
>> [GCC 4.4.4 20100726 (Red Hat 4.4.4-13)] on linux2
>> TclVersion 8.5  TkVersion 8.5
>> with the program running on the above and the output being X'ed to an
>> OSX Mountain Lion iMac.
>> 
> (...)
>> Same with
>> 
>> Python 2.7.2 (default, Jun 20 2012, 16:23:33) 
>> [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on
>> darwin
>>>>> import Tkinter
>>>>> Tkinter.TclVersion
>> 8.5
>>>>> Tkinter.TkVersion
>> 8.5
> 
> Ok, then it is at least not a bug specific for my version of Tk.
> 
> Experimenting a little I just found that it is possible to update the
> image programatically if I force tk to redraw the button e.g. with this
> modification of my example:
> 
> def test(event=None):
>    im.configure(data=icon2)
>    b.config(state=b['state'])
> 
> root.bind('<F1>', test)
> 
> It also works with b.config(image=b['image']) or
> b.config(text=b['text']). Hmmm...
> 
> Another try, I changed my example callback into:
> 
> s = ttk.Style()
> def test(event=None):
>    im.configure(data=icon2)
>    s.theme_use(s.theme_use())
> 
> root.bind('<F1>', test)
> 
> Here this works too, and this one might actually be usable!
> Can you confirm that this does the trick?

Yup.  The "Another try" works here on both systems.

Bob




More information about the Tkinter-discuss mailing list