[1023] PyQt: GUI for Python
ref: PyQt5 tutorial
ref: PyQt6 Widgets
Example:
Script:
from PyQt6.QtWidgets import QApplication, QHBoxLayout, QLabel, QWidget, QLineEdit, QPushButton, QVBoxLayout, QMessageBox from PyQt6.QtGui import QIcon import pyautogui app = QApplication([]) window = QWidget() # Window's title window.setWindowTitle("TestApp") # Window's icon window.setWindowIcon(QIcon(r"D:\OneDrive\OneDrive - Land Insight Resources\Bingnan_Li\01_Tasks\2024\47_2024_07_08_Python_GUI\icon2.png")) # Window's size # window.resize(250, 80) # window.setFixedSize(250, 80) window.setFixedWidth(250) ################################################################################################### # For name label_name = QLabel("Name:") line_edit_name = QLineEdit() line_layout_name = QHBoxLayout() line_layout_name.addWidget(label_name) line_layout_name.addWidget(line_edit_name) # For age label_age = QLabel("Age:") line_edit_age = QLineEdit() line_layout_age = QHBoxLayout() line_layout_age .addWidget(label_age ) line_layout_age .addWidget(line_edit_age ) # For city label_city = QLabel("City:") line_edit_city = QLineEdit() line_layout_city = QHBoxLayout() line_layout_city .addWidget(label_city ) line_layout_city .addWidget(line_edit_city ) layout_window = QVBoxLayout() layout_window.addLayout(line_layout_name) layout_window.addLayout(line_layout_age) layout_window.addLayout(line_layout_city) ################################################################################################### # For buttons button_top = QPushButton('Get all above info') button_bottom = QPushButton('Open Chrome') layout_button = QHBoxLayout() layout_button.addWidget(button_top) layout_button.addWidget(button_bottom) layout_window.addLayout(layout_button) window.setLayout(layout_window) def on_button_top_clicked(): alert = QMessageBox() text_name = line_edit_name.text() text_age = line_edit_age.text() text_city = line_edit_city.text() alert.setText(f'My name is {text_name} and I am {text_age} years old now. \n Also, I am from {text_city}!') alert.exec() button_top.clicked.connect(on_button_top_clicked) def on_button_bottom_clicked(): pyautogui.hotkey("win", "2") #alert = QMessageBox() #alert.setText('You clicked the bottom button!') #alert.exec() button_bottom.clicked.connect(on_button_bottom_clicked) window.show() app.exec()
分类:
Python Study
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2015-07-08 【168】ENVI入门系列
2015-07-08 【167】IDL 中相关技巧
2012-07-08 【057】百场网球比赛高清下载地址
2012-07-08 【056】我的电子产品