在Debian上进行Python图形界面(GUI)开发可以通过多种库和工具实现,以下是一些常见的方法和步骤:
pip install PyQt5
pip install PyQt5-tools
安装完PyQt5-tools后,Qt Designer会自动集成,无需单独安装。pyuic5
命令将.ui
文件转换为Python代码:pyuic5 my_window.ui -o my_window.py
Ui_MainWindow
并添加事件处理函数:from PyQt5 import QtWidgets
from my_window import Ui_MainWindow
class MyWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.pushButton.clicked.connect(self.on_click)
def on_click(self):
print("按钮被点击了!")
self.pushButton.clicked.connect(self.handle_click)
setStyleSheet
方法设置控件样式:self.pushButton.setStyleSheet("QPushButton {background-color: #4CAF50; border: none; color: white; padding: 15px 32px; border-radius: 5px;}")
pip install customtkinter
import customtkinter as ctk
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("dark-blue")
root = ctk.CTk()
root.geometry("500x350")
root.title("Login System")
def login():
print("Login Successful")
frame = ctk.CTkFrame(master=root)
frame.pack(pady=20, padx=60, fill="both", expand=True)
label = ctk.CTkLabel(master=frame, text="Login System", font=("Roboto", 24))
label.pack(pady=12, padx=10)
entry_username = ctk.CTkEntry(master=frame, placeholder_text="Username")
entry_username.pack(pady=12, padx=10)
entry_password = ctk.CTkEntry(master=frame, placeholder_text="Password", show="*")
entry_password.pack(pady=12, padx=10)
button = ctk.CTkButton(master=frame, text="Login", command=login)
button.pack(pady=12, padx=10)
checkbox = ctk.CTkCheckBox(master=frame, text="Remember Me")
checkbox.pack(pady=12, padx=10)
root.mainloop()
pip install easygui
import easygui as eg
response = eg.msgbox("文件保存成功!", title="系统提示", ok_button="确定")
print(f"用户操作: {response}")
options = ["新建项目", "打开项目", "退出系统"]
choice = eg.indexbox("请选择操作:", choices=options)
print('choice:', choice)
print(f"选中操作: {options[choice] if choice is not None else '取消'}")
path = eg.fileopenbox(msg="选择数据文件", title="文件选择器", default="*.csv", filetypes=["*.csv", "*.xlsx"])
print(f"选中文件: {path if path else '未选择'}")
通过以上方法,你可以在Debian上使用不同的Python GUI库进行图形界面开发。选择合适的库取决于你的具体需求和偏好。