Introduction to tkinter.messagebox module When developing a Tkinter application, you often want to notify users about the events that occurred. For example, when users click the save button, you want to notify them that the record has been saved successfully. If an error occurred, for example, the database server is notContinue Reading

You’ll convert the temperature converter application to a new one that uses object-oriented programming approach: First, define a class called TemperatureConverter. The class has one static method that converts a temperature from Fahrenheit to Celsius: import tkinter as tk from tkinter import ttk from tkinter.messagebox import showerror class TemperatureConverter: @staticmethod def fahrenheit_to_celsius(f): return (f – 32)Continue Reading

In the previous tutorial, you’ve learned how to subclass the Tkinter.Tk class. However, a Tkinter application should have only one Tk instance. Therefore, it’s common to inherit from the ttk.Frame class and use the subclass in the root window. To inherit the ttk.Frame class, you use the following syntax: class MainFrame(ttk.Frame): passCode language: Python (python) Since a Frame needs aContinue Reading

Defining a Tkinter object-oriented window The following simple program creates a root window and displays it on the screen: import tkinter as tk root = tk.Tk() root.mainloop()Code language: Python (python) When the program is getting more complex, you can use an object-oriented programming approach to make the code more organized. The following program achievesContinue Reading

Changing the cursor for the root window The root window has only two cursors: The Normal cursor has the value of “” while the busy cursor has the value of “watch”. The following program shows how to change the cursor of the root window from normal to busy: import tkinter as tk rootContinue Reading

Introduction to the Tkinter canvas widget The canvas widget is the most flexible widget in Tkinter. The Canvas widget allows you to build anything from custom widgets to complete user interfaces. The canvas widget is a blank area on which you can draw figures, create text, and place images. ToContinue Reading

Introduction to the Tkinter Treeview widget A Treeview widget allows you to display data in both tabular and hierarchical structures. To create a Treeview widget, you use the ttk.Treeview class: tree = ttk.Treeview(container, **options)Code language: Python (python) A Treeview widget holds a list of items. Each item has one or more columns.Continue Reading

Introduction to the Tkinter Notebook widget The Notebook widget allows you to select pages of contents by clicking on tabs: When you click one of these tabs, the Notebook widget will display a child pane associated with the selected tab. Typically, a child pane is a Frame widget. To create a Notebook widget, you use the ttk.Notebook class as follows:Continue Reading