[Tkinter-discuss] Changing image data in ttk does not work
Michael Lange
klappnase at web.de
Sun Dec 18 17:47:26 CET 2011
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
More information about the Tkinter-discuss
mailing list