Ttk style inheritance

You know the drill by now—open up a blank file and fill in the following code:

import tkinter as tkimport tkinter.ttk as ttkwin = tk.Tk()regular_button = ttk.Button(win, text="regular button")small_button = ttk.Button(win, text="small button", style="small.TButton")big_button = ttk.Button(win, text="big button", style="big.TButton")big_dangerous_button = ttk.Button(win, text="big dangerous", style="danger.big.TButton")small_dangerous_button = ttk.Button(win, text="small dangerous", style="danger.small.TButton")

After the imports and main window, we create five buttons. Each button will have different styling added to it:

  • The first has no style argument, so will only have the global styling applied to it.
  • The second ...

Get Tkinter GUI Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.