alex_bn_lee

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

[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()

 

posted on   McDelfino  阅读(5)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 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】我的电子产品
点击右上角即可分享
微信分享提示