[Tutor] tkinter ttk style
Phil
phillor9 at gmail.com
Wed May 8 23:23:38 EDT 2024
I've spent a lot of time reading documentation and tying to adapt
examples to set two ttk buttons to different background colours without
success.
Using the following code both buttons have the same background colour.
self.style = ttk.Style()
self.style.configure("TButton", background="orange")
self.style.configure("TButton.another_button", background="pink")
exit_button = ttk.Button(frame, text="Exit", command=self.destroy)
exit_button.grid(column=3, row=3, padx=5, pady=5)
anothert_button = ttk.Button(frame, etc)
I've even resorted to asking my AI friend for help and eventually I got
working code that included the following. Although it works almost
perfectly (the pink button is smaller than the exit button for some
reason) the code seems to be unnecessarily convoluted.
self.style.layout(
"TButton.another_button",
[
(
"Button.focus",
{
"children": [
(
"Button.padding",
{"children": [("Button.label",
{"sticky": "nswe"})]},
)
]
},
)
],
)
Again, any tips will be greatly appreciated.
--
Regards,
Phil
More information about the Tutor
mailing list