How it works...

A common way to start using themed widgets is to import the tkinter.ttk module using the import ... as syntax. Thus, we can easily identify standard widgets with the tk name and themed widget with the ttk name:

import tkinter as tk
import tkinter.ttk as ttk

As you might have noticed in the preceding code, replacing widgets from the tkinter module with their equivalents from tkinter.ttk is as easy as changing the alias name:

import tkinter as tk
import tkinter.ttk as ttk

# ...
entry_1 = tk.Entry(root)
entry_2 = ttk.Entry(root)

In our example, we did so for the ttk.Frame, ttk.Label, ttk.Entry, ttk.LabelFrame, and ttk.Radiobutton widgets. These classes accept almost the same basic options as their standard Tkinter equivalents; indeed, they actually are their subclasses.

However, this translation is simple because we are not porting any styling options, such as foreground or background. In themed widgets, these keywords are used separately through the ttk.Style class, which we will cover in another recipe.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset