Python tkinter (GUI programming) module tutorial: create a beautiful graphical user interface

As the program becomes more and more complex, the command line can no longer meet our needs, and the graphical interface has become the current mainstream interface design. In Python, tkinter is an easy-to-use GUI programming tool that can help us quickly create a graphical user interface. This article will introduce in detail how to use the Python tkinter module to create a beautiful graphical user interface through examples.

install tkinter

If you are using Python 3.1 or later, then Tkinter is already installed on your computer. If you are using an older version of Python then you will need to install the Tkinter module. Enter the following command on the command line:

sudo apt-get install python3-tk  

This will install Tkinter on your computer.

create window

Let's start with a simple example, creating an empty window:

import tkinter as tk
 
root = tk.Tk()
root.mainloop()

This will display a blank window and keep the window open until you click the close button. We can add various controls in the window, such as labels, buttons, etc.

add tag

Guess you like

Origin blog.csdn.net/update7/article/details/131180149