Re: ttk styles - is it possible to have one per widget?
Michael Lange <[email protected]> Sat, 23 Nov 2019 18:02:07 +0100
| Newsgroups | gmane.comp.python.tkinter |
|---|---|
| Message-ID | <[email protected]> |
Hi, On Fri, 22 Nov 2019 16:00:07 +0000 Mike Barnett <[email protected]> wrote: > Hmmm... I didn't see am email go out for this. Did anyone get this > email? > sure :) > What I am trying to do is "style" ttk widgets in a way that each one > can have their own unique settings. I've not found code or pseudo-code > that does what I'm looking for. > > Is it possible for ttk widgets to work like tk widgets in that each can > have their own unique settings like background color, text color, etc? You can do this by defining custom styles that inherit their properties from the widget's default style and set some or other properties to custom values, as for example: from tkinter import * from tkinter import ttk root=Tk() style = ttk.Style() style.configure('my.TButton', background='red') style.configure('myOther.TButton', background='blue') ttk.Button(root, style='my.TButton', text='foo').pack() ttk.Button(root, style='myOther.TButton', text='bar').pack() root.mainloop() I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. The games have always strengthened us. Death becomes a familiar pattern. We don't fear it as you do. -- Proconsul Marcus Claudius, "Bread and Circuses", stardate 4041.2