Reputation: 561
I'm trying to learn how to create a custom ttk style by following this documentition: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-style-layer.html
Here is the code:
self.style = ttk.Style()
self.style.configure("ciao.TLabel", bg="red")
poplabel = ttk.Label(self.root, text="ciao", style="ciao.TLabel")
poplabel.place(x=0, y=530)
The problem is that the label style remains the default one and not the "ciao.TLabel".
Upvotes: 1
Views: 1203
Reputation: 8234
You are encountering the problem because background of a ttk.Label
is not customised from changing style but by changing the background option in w = ttk.Label(parent, option=value, ...)
.
To change background colour from an existing colour, you need to do:
poplabel.configure(background='red')
or poplabel[background]='red'
.
To change background of default while creating the ttk.label, type:
poplabel = ttk.Label(self.root, text="ciao", background="red")
Update: My bad, you can change the background as mentioned above and also by using style. L'ultimo is correct. :)
Upvotes: 0
Reputation: 561
The problem is that "bg" does not exist on ttk. Only "background" does, in fact
self.style.configure("ciao.TLabel", background="red")
works.
Upvotes: 1