Label behavior's difference between tkinter and ttk
Mark Lawrence
breamoreboy at yahoo.co.uk
Tue Apr 5 11:10:03 EDT 2016
On 05/04/2016 07:57, ast wrote:
> Hello
>
> I currently migrate a GUI from tkinter to ttk and I found a problem
>
> Here is a piece of code, with comments which explain what is wrong.
>
> import tkinter as tk
> import tkinter.ttk as ttk
>
> root = tk.Tk()
>
> BITMAP0 = """
> #define zero_width 24
> #define zero_height 32
> static char zero_bits[] = {
> 0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f,
> 0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00,
> 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
> 0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
> 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00,
> 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
> 0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f,
> 0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00
> };
> """
>
> img = tk.BitmapImage(data=BITMAP0, foreground='white', background='black')
>
> # This Label comes from ttk
>
> label = ttk.Label(root, image=img)
>
> # This Label comes from tk. To be uncommented to test behavior'difference
> # label = tk.Label(root, image=img)
>
> label.pack()
>
> # The graphic is not refreshed after entering following commands
> # when Label comes from ttk. You have to fly over the label with # the
> mouse to get the right color.
> # The graphic is immediately updated when Label comes from tk
>
> # Enter these commands by hand, in a shell
>
> img.config(foreground='red')
> img.config(foreground='lime')
> img.config(foreground='yellow')
>
>
> It looks like a ttk bug, isn't it ?
> I am using python 3.5.1
>
> I tried a root.update_idletasks() to refresh the graphic
> but it changed nothings.
>
I'm no tkinter expert, but I do know that there is a huge difference
between the way that tk and ttk widgets are configured. Here are a few
links that I hope will give you an idea.
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-Label.html
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-layouts.html
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-map.html
http://www.tkdocs.com/tutorial/styles.html
In the latter you might like to note that there is a section called
"Sound Difficult to you?". It's well worth the read.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Python-list
mailing list