O'Reilly logo

Tkinter GUI Programming by Example by David Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required