Changing image data in ttk does not work

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Changing image data in ttk does not work

Michael Lange
Hi,

I just noticed an odd behavior in ttk, when I try to change the image
data of a ttk.Label's image, the image isn't actually updated. A simple
code example:

########################################
from Tkinter import *
import ttk

icon1 = ('R0lGODlhEAAQAJEAANnZ2QAAAISEAP///yH5BAEAAAAALAAAAAAQABAAAAJ'
    'WhI9pFB8RIIRC+BYQFqQQvkWEBSmEbyFhQQrhW0hYkEL4FhIWpBC+hYQFSYxvIgF'
    'AoXy0AAiSGP8kAIIkxgcICSBEQvEBQgIIkVB8gJAAAhgfj+BjWgEAOw==')
icon2 = ('R0lGODlhEAAQAKIAANnZ2QAAAP///4SEhP//AP///////////yH5BAEAAAA'
    'ALAAAAAAQABAAAANZCLrcjqG7CLqBoquBoBuCoSqBoBsouhoIuiEYqrKBoIGiqwE'
    'YEIChyxAIEYGgywEYgKHLDAgRCLozgwABARgIukSEABEBGLq8gAEQCLobgAEAgKH'
    'LgaDLzZgAOw==')
root = Tk()
im = PhotoImage(data=icon1)
Label(root, image=im, text='Tkinter', compound='left').pack(
      padx=100, pady=50)
ttk.Label(root, image=im, text='ttk', compound='left').pack(
      padx=100, pady=50)

current = 1
def swapimage():
    global current
    if current == 1:
        im.configure(data=icon2)
        current = 2
    else:
        im.configure(data=icon1)
        current = 1
    root.after(1000, swapimage)
root.after(1000, swapimage)

root.mainloop()
########################################

When I run this code, the image in the Tkinter.Label changes every
second, as expected, but the ttk.Label's image doesn't. Is this
documented somewhere or is this a bug?
Adding update_idletasks() or even update() to swapimage() does not help
either.
I know that I can change the image by doing
   ttklabel.configure(image=some_other_photoimage)
but I thought changing the image data on the fly should work, too.

Btw., the system is debian linux, tcl version is 8.5.8 .

Regards

Michael

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

We do not colonize.  We conquer.  We rule.  There is no other way for us.
                -- Rojan, "By Any Other Name", stardate 4657.5
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Changing image data in ttk does not work

Michael Lange
Hi again,

Thus spoketh Michael Lange <[hidden email]>
unto us on Sun, 18 Dec 2011 17:47:26 +0100:

> Hi,
>
> I just noticed an odd behavior in ttk, when I try to change the image
> data of a ttk.Label's image, the image isn't actually updated. A simple
> code example:
(...)

I just noticed that it is even starnger; actually the image *is* updated,
as soon as the mouse pointer enters or leaves the ttk.Label . So I
think this really appears to be a (maybe Tk-version specific?) bug.
Can anyone confirm this behavior?

Regards

Michael

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

        "I think they're going to take all this money that we spend now
on war and death --"
        "And make them spend it on life."
                -- Edith Keeler and Kirk, "The City on the Edge of
Forever", stardate unknown.
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Changing image data in ttk does not work

Martin B.-4
V Sun, 18 Dec 2011 18:01:02 +0100
Michael Lange <[hidden email]> napsáno:

same here. tested with py2.7 and py3.2
Tk version 8.5.11 on ArchLinux i686

> Hi again,
>
> Thus spoketh Michael Lange <[hidden email]>
> unto us on Sun, 18 Dec 2011 17:47:26 +0100:
>
> > Hi,
> >
> > I just noticed an odd behavior in ttk, when I try to change the
> > image data of a ttk.Label's image, the image isn't actually
> > updated. A simple code example:
> (...)
>
> I just noticed that it is even starnger; actually the image *is*
> updated, as soon as the mouse pointer enters or leaves the
> ttk.Label . So I think this really appears to be a (maybe Tk-version
> specific?) bug. Can anyone confirm this behavior?
>
> Regards
>
> Michael
>
> .-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-.
> --- ... .--. . .-.
>
> "I think they're going to take all this money that we spend
> now on war and death --"
> "And make them spend it on life."
> -- Edith Keeler and Kirk, "The City on the Edge of
> Forever", 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
Reply | Threaded
Open this post in threaded view
|

Re: Changing image data in ttk does not work

Martin B.-4
V Sun, 18 Dec 2011 20:43:52 +0100
Martin B <[hidden email]> napsáno:

ugly solution i was found for now is 2 PhotoImages.

if current == 1:
        label1.config(image=photoimage1)
        label2.config(image=photoimage1)
        current=0
else:
        label1.config(image=photoimage2)
        label2.config(image=photoimage2)
        current=0

i never use PhotoImage.config() until this test.
i always used Label.config() for changing
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Changing image data in ttk does not work

Michael Lange
Hi,

Thus spoketh Martin B <[hidden email]>
unto us on Sun, 18 Dec 2011 21:09:52 +0100:

> V Sun, 18 Dec 2011 20:43:52 +0100
> Martin B <[hidden email]> napsáno:
>
> ugly solution i was found for now is 2 PhotoImages.
>
> if current == 1:
> label1.config(image=photoimage1)
> label2.config(image=photoimage1)
> current=0
> else:
> label1.config(image=photoimage2)
> label2.config(image=photoimage2)
> current=0
>
> i never use PhotoImage.config() until this test.
> i always used Label.config() for changing

Yes this works, but unfortunately this breaks the pseudo-animated-gif
class I've been using. For now I think I will stick with the
Tkinter.Label, it does not seem to be a problem as long as you don't want
to change the theme on the fly.

Regards

Michael

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

Actual war is a very messy business.  Very, very messy business.
                -- Kirk, "A Taste of Armageddon", stardate 3193.0
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Changing image data in ttk does not work

Emiliano Gavilán
In reply to this post by Michael Lange
2011/12/18 Michael Lange <[hidden email]>:
> Hi,
>
> I just noticed an odd behavior in ttk, when I try to change the image
> data of a ttk.Label's image, the image isn't actually updated. A simple
> code example:

Is a bug in ttk redisplay code. I've reported it upstream (bug 3462273).
Thanks for spotting.

Regards

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