Python Tkinter Tutorial: Create GUI Applications

Using the tkinter module in Python allows you to create GUI (Graphical User Interface) applications. Here is a simple example:

import tkinter as tk

# 创建一个窗口
root = tk.Tk()

# 添加一个标签
label = tk.Label(root, text="Hello, World!")
label.pack()

# 运行窗口的主循环
root.mainloop()

In this example, we start by importing the tkinter module, then create a window (root). We add a label to the window displaying the text “Hello, World!”. Finally, we run the main loop of the window to display the GUI.

Apart from labels, tkinter also offers various other GUI components such as buttons, text boxes, checkboxes, etc., which can be added to the window as needed. Using these components, you can create different types of GUI applications.

bannerAds