search
HomeBackend DevelopmentPython TutorialSeven essential GUI libraries for Python, you must learn them this time!


GUI (Graphical User Interface), as the name suggests, uses graphics to display the computer operation interface. , more convenient and intuitive.


Corresponding to it is CUI (Command Line User Interaction), which is a common Dos command line operation. You need to memorize some commonly used commands. For ordinary people, it is quite difficult to learn how to operate them.


A good-looking and easy-to-use GUI can greatly improve everyone’s experience and efficiency.


For example, if you want to develop a calculator, if it is just a program input and output window, there will be no user experience. .


So it becomes necessary to develop a small graphical window.


Today, Xiao F will introduce to you seven essential GUI libraries for Python, each of which is worth learning.



##01. PyQt5


##PyQt5 is developed by Riverbank Computing. Built on the Qt framework, it is a cross-platform framework that can create applications for various platforms, including: Unix, Windows, and Mac OS.


PyQt combines Qt and Python. It's not just a GUI toolkit. Also included are threads, Unicode, regular expressions, SQL databases, SVG, OpenGL, XML and a full-featured web browser, as well as many rich collections of GUI widgets.


Use pip to install it.


##
# 安装PyQt5
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple PyQt5


After successful installation, here is a simple example of Hello Word.


##

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout

# 建立application对象
app = QApplication(sys.argv)
# 建立窗体对象
w = QWidget()
# 设置窗体大小
w.resize(500, 500)

# 设置样式
w.layout = QVBoxLayout()
w.label = QLabel("Hello World!")
w.label.setStyleSheet("font-size:25px;margin-left:155px;")
w.setWindowTitle("PyQt5 窗口")
w.layout.addWidget(w.label)
w.setLayout(w.layout)

# 显示窗体
w.show()
# 运行程序
sys.exit(app.exec_())


The results are as follows.


Seven essential GUI libraries for Python, you must learn them this time!


##Document address:

https://riverbankcomputing.com/software/pyqt/intro

Tutorial link:

https://www.guru99.com/pyqt-tutorial.html



##02. Tkinter


Tkinter is one of the most popular GUI libraries in Python. Due to itssimple and easy-to-learn syntax, it has become one of the first choices for GUI development beginners .


Tkinter provides various widgets such as labels, buttons, text fields, checkboxes and scroll buttons, etc. .


Supports Grid (grid) layout. Since most of our programs are displayed in rectangles, even complex designs can be developed easily. Become simpler.


# 安装tkinter
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tkinter


下面使用Tkinter设计一个BMI计算器。


以重量和高度作为输入,并在弹出框中返回BMI系数作为输出。


from tkinter import *
from tkinter import messagebox

def get_height():
    # 获取身高数据(cm)
    height = float(ENTRY2.get())
    return height

def get_weight():
    # 获取体重数据(kg)
    weight = float(ENTRY1.get())
    return weight

def calculate_bmi():
    # 计算BMI系数
    try:
        height = get_height()
        weight = get_weight()
        height = height / 100.0
        bmi = weight / (height ** 2)
    except ZeroDivisionError:
        messagebox.showinfo("提示", "请输入有效的身高数据!!")
    except ValueError:
        messagebox.showinfo("提示", "请输入有效的数据!")
    else:
        messagebox.showinfo("你的BMI系数是: ", bmi)

if __name__ == '__main__':
    # 实例化object,建立窗口TOP
    TOP = Tk()
    TOP.bind("<Return>", calculate_bmi)
    # 设定窗口的大小(长 * 宽)
    TOP.geometry("400x400")
    # 窗口背景颜色
    TOP.configure(background="#8c52ff")
    # 窗口标题
    TOP.title("BMI 计算器")
    TOP.resizable(width=False, height=False)
    LABLE = Label(TOP, bg="#8c52ff", fg="#ffffff", text="欢迎使用 BMI 计算器", font=("Helvetica", 15, "bold"), pady=10)
    LABLE.place(x=55, y=0)
    LABLE1 = Label(TOP, bg="#ffffff", text="输入体重(单位:kg):", bd=6,
                   font=("Helvetica", 10, "bold"), pady=5)
    LABLE1.place(x=55, y=60)
    ENTRY1 = Entry(TOP, bd=8, width=10, font="Roboto 11")
    ENTRY1.place(x=240, y=60)
    LABLE2 = Label(TOP, bg="#ffffff", text="输入身高(单位:cm):", bd=6,
                   font=("Helvetica", 10, "bold"), pady=5)
    LABLE2.place(x=55, y=121)
    ENTRY2 = Entry(TOP, bd=8, width=10, font="Roboto 11")
    ENTRY2.place(x=240, y=121)
    BUTTON = Button(bg="#000000", fg=&#39;#ffffff&#39;, bd=12, text="BMI", padx=33, pady=10, command=calculate_bmi,
                    font=("Helvetica", 20, "bold"))
    BUTTON.grid(row=5, column=0, sticky=W)
    BUTTON.place(x=115, y=250)
    TOP.mainloop()


界面如下。


Seven essential GUI libraries for Python, you must learn them this time!


When there is no data, click the BMI button and there will be a corresponding prompt.


Let’s use the correct data to see the results.


Seven essential GUI libraries for Python, you must learn them this time!


#It feels good to use.



#03. Kivy


Kivy是另一个开源的Python库,最大的优点就是可以快速地编写移动应用程序(手机)。


Kivy可以在不同的平台上运行,包括Windows、Mac OS、Linux、Android、iOS和树莓派。


此外也是免费使用的,获得了MIT许可。


# 安装kivy
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple kivy


一个基于Kivy的Hello World窗口。


from kivy.app import App
from kivy.uix.button import Button

class TestApp(App):
    def build(self):
        return Button(text=" Hello Kivy World ")

TestApp().run()


结果如下。


Seven essential GUI libraries for Python, you must learn them this time!



04. wxPython


wxPython是一个跨平台GUI的Python库,可轻松创建功能强大稳定的GUI,毕竟是用C++编写的~


目前,支持Windows,Mac OS X,macOS和Linux。


使用wxPython创建的应用程序(GUI)在所有平台上都具有原生外观。


# 安装wxPython
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple wxPython


下面使用wxPython创建一个基本的GUI示例。


import wx

myapp = wx.App()
init_frame = wx.Frame(parent=None, title=&#39;WxPython 窗口&#39;)

init_frame.Show()
myapp.MainLoop()


结果如下。


Seven essential GUI libraries for Python, you must learn them this time!


Documentation link:https://www.wxpython.org/



##05. PySimpleGUI


PySimpleGUI is also a GUI framework based on Python. Can easily make customized GUI.


Adopts the four most popular GUI frameworks QT, Tkinter, WxPython and Remi, which can implement most sample codes and reduce The learning difficulty is .


Remi将应用程序的界面转换为HTML,以便在Web浏览器中呈现。


# 安装PySimpleGUI
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple PySimpleGUI


下面是一个简单的案例。


import PySimpleGUI as sg

layout = [[sg.Text("测试 PySimpleGUI")], [sg.Button("OK")]]
window = sg.Window("样例", layout)
while True:
    event, values = window.read()
    if event == "OK" or event == sg.WIN_CLOSED:
        break
window.close()


结果如下。


Seven essential GUI libraries for Python, you must learn them this time!


Click the OK button and the window disappears.



#06. PyGUI


##PyGUI is a GUI framework known for its simple API, which reduces the gap between Python applications and the underlying GUI of the platform amount of code.


##Lightweight API can make your application run more smoothly. Faster.

At the same time, it also provides open source code and cross-platform projects. Currently runs on Unix-based systems, Windows and Mac OS.


Python2 and Python3 are both supported.

Document address:

https: //www.cosc.canterbury.ac.nz/greg.ewing/python_gui/

Tutorial link:

https://realpython.com/pysimplegui-python/



07. Pyforms


##Pyforms is a cross-platform framework for developing GUI applications.


Seven essential GUI libraries for Python, you must learn them this time!


#Pyforms is a Python2. 7/3.x cross-environment graphics application development framework, modularization and code reuse can save a lot of work.


Allows applications to run on the desktop, web and terminal without modifying the code.


# 安装PyFroms
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple PyFroms


文档地址:https://pyforms.readthedocs.io/en/v4/


The above is the detailed content of Seven essential GUI libraries for Python, you must learn them this time!. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:Python当打之年. If there is any infringement, please contact admin@php.cn delete
Python's Execution Model: Compiled, Interpreted, or Both?Python's Execution Model: Compiled, Interpreted, or Both?May 10, 2025 am 12:04 AM

Pythonisbothcompiledandinterpreted.WhenyourunaPythonscript,itisfirstcompiledintobytecode,whichisthenexecutedbythePythonVirtualMachine(PVM).Thishybridapproachallowsforplatform-independentcodebutcanbeslowerthannativemachinecodeexecution.

Is Python executed line by line?Is Python executed line by line?May 10, 2025 am 12:03 AM

Python is not strictly line-by-line execution, but is optimized and conditional execution based on the interpreter mechanism. The interpreter converts the code to bytecode, executed by the PVM, and may precompile constant expressions or optimize loops. Understanding these mechanisms helps optimize code and improve efficiency.

What are the alternatives to concatenate two lists in Python?What are the alternatives to concatenate two lists in Python?May 09, 2025 am 12:16 AM

There are many methods to connect two lists in Python: 1. Use operators, which are simple but inefficient in large lists; 2. Use extend method, which is efficient but will modify the original list; 3. Use the = operator, which is both efficient and readable; 4. Use itertools.chain function, which is memory efficient but requires additional import; 5. Use list parsing, which is elegant but may be too complex. The selection method should be based on the code context and requirements.

Python: Efficient Ways to Merge Two ListsPython: Efficient Ways to Merge Two ListsMay 09, 2025 am 12:15 AM

There are many ways to merge Python lists: 1. Use operators, which are simple but not memory efficient for large lists; 2. Use extend method, which is efficient but will modify the original list; 3. Use itertools.chain, which is suitable for large data sets; 4. Use * operator, merge small to medium-sized lists in one line of code; 5. Use numpy.concatenate, which is suitable for large data sets and scenarios with high performance requirements; 6. Use append method, which is suitable for small lists but is inefficient. When selecting a method, you need to consider the list size and application scenarios.

Compiled vs Interpreted Languages: pros and consCompiled vs Interpreted Languages: pros and consMay 09, 2025 am 12:06 AM

Compiledlanguagesofferspeedandsecurity,whileinterpretedlanguagesprovideeaseofuseandportability.1)CompiledlanguageslikeC arefasterandsecurebuthavelongerdevelopmentcyclesandplatformdependency.2)InterpretedlanguageslikePythonareeasiertouseandmoreportab

Python: For and While Loops, the most complete guidePython: For and While Loops, the most complete guideMay 09, 2025 am 12:05 AM

In Python, a for loop is used to traverse iterable objects, and a while loop is used to perform operations repeatedly when the condition is satisfied. 1) For loop example: traverse the list and print the elements. 2) While loop example: guess the number game until you guess it right. Mastering cycle principles and optimization techniques can improve code efficiency and reliability.

Python concatenate lists into a stringPython concatenate lists into a stringMay 09, 2025 am 12:02 AM

To concatenate a list into a string, using the join() method in Python is the best choice. 1) Use the join() method to concatenate the list elements into a string, such as ''.join(my_list). 2) For a list containing numbers, convert map(str, numbers) into a string before concatenating. 3) You can use generator expressions for complex formatting, such as ','.join(f'({fruit})'forfruitinfruits). 4) When processing mixed data types, use map(str, mixed_list) to ensure that all elements can be converted into strings. 5) For large lists, use ''.join(large_li

Python's Hybrid Approach: Compilation and Interpretation CombinedPython's Hybrid Approach: Compilation and Interpretation CombinedMay 08, 2025 am 12:16 AM

Pythonusesahybridapproach,combiningcompilationtobytecodeandinterpretation.1)Codeiscompiledtoplatform-independentbytecode.2)BytecodeisinterpretedbythePythonVirtualMachine,enhancingefficiencyandportability.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use