当前位置: 首页 > news >正文

Qt Designer and Python: Build Your GUI

1.install pyside6

2.pyside6-designer.exe 发送到桌面快捷方式

在Python安装的所在 Scripts 文件夹下找到此文件。如C:\Program Files\Python312\Scripts

 

3. 打开pyside6-designer 设计UI

4.保存为simple.ui 文件,再转成py文件

用代码执行 pyside6-uic.exe simple.ui -o simple.py

生成源文件simple.py:

# -*- coding: utf-8 -*-################################################################################
## Form generated from reading UI file 'simple.ui'
##
## Created by: Qt User Interface Compiler version 6.8.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,QMetaObject, QObject, QPoint, QRect,QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,QFont, QFontDatabase, QGradient, QIcon,QImage, QKeySequence, QLinearGradient, QPainter,QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QAbstractButton, QApplication, QDialog, QDialogButtonBox,QLabel, QSizePolicy, QTextEdit, QWidget)class Ui_Dialog(object):def setupUi(self, Dialog):if not Dialog.objectName():Dialog.setObjectName(u"Dialog")Dialog.resize(736, 520)self.buttonBox = QDialogButtonBox(Dialog)self.buttonBox.setObjectName(u"buttonBox")self.buttonBox.setGeometry(QRect(50, 360, 341, 32))self.buttonBox.setOrientation(Qt.Orientation.Horizontal)self.buttonBox.setStandardButtons(QDialogButtonBox.StandardButton.Cancel|QDialogButtonBox.StandardButton.Ok)self.txtName = QTextEdit(Dialog)self.txtName.setObjectName(u"txtName")self.txtName.setGeometry(QRect(340, 110, 221, 31))self.txtpassword = QTextEdit(Dialog)self.txtpassword.setObjectName(u"txtpassword")self.txtpassword.setGeometry(QRect(340, 170, 221, 31))self.label = QLabel(Dialog)self.label.setObjectName(u"label")self.label.setGeometry(QRect(230, 120, 61, 21))font = QFont()font.setPointSize(14)self.label.setFont(font)self.label.setLineWidth(3)self.label_2 = QLabel(Dialog)self.label_2.setObjectName(u"label_2")self.label_2.setGeometry(QRect(220, 180, 71, 21))self.label_2.setFont(font)self.retranslateUi(Dialog)self.buttonBox.accepted.connect(Dialog.objectName)self.buttonBox.rejected.connect(Dialog.objectName)QMetaObject.connectSlotsByName(Dialog)# setupUidef retranslateUi(self, Dialog):Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"Dialog", None))self.label.setText(QCoreApplication.translate("Dialog", u"\u59d3\u540d", None))self.label_2.setText(QCoreApplication.translate("Dialog", u"\u5bc6\u7801", None))# retranslateUi

加上点击事件

# -*- coding: utf-8 -*-################################################################################
## Form generated from reading UI file 'simple.ui'
##
## Created by: Qt User Interface Compiler version 6.8.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,QMetaObject, QObject, QPoint, QRect,QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,QFont, QFontDatabase, QGradient, QIcon,QImage, QKeySequence, QLinearGradient, QPainter,QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QAbstractButton, QApplication, QDialog, QDialogButtonBox,QLabel, QSizePolicy, QTextEdit, QWidget,QVBoxLayout)class Ui_Dialog(object):""""""def setupUi(self, Dialog):""":param Dialog::return:"""if not Dialog.objectName():Dialog.setObjectName(u"Dialog")Dialog.resize(736, 520)self.buttonBox = QDialogButtonBox(Dialog)self.buttonBox.setObjectName(u"buttonBox")self.buttonBox.setGeometry(QRect(90, 280, 341, 32))self.buttonBox.setOrientation(Qt.Orientation.Horizontal)self.buttonBox.setStandardButtons(QDialogButtonBox.StandardButton.Cancel|QDialogButtonBox.StandardButton.Ok)self.txtName = QTextEdit(Dialog)self.txtName.setObjectName(u"txtName")self.txtName.setGeometry(QRect(340, 110, 221, 31))self.txtpassword = QTextEdit(Dialog)self.txtpassword.setObjectName(u"txtpassword")self.txtpassword.setGeometry(QRect(340, 170, 221, 31))self.label = QLabel(Dialog)self.label.setObjectName(u"label")self.label.setGeometry(QRect(230, 120, 61, 21))font = QFont()font.setPointSize(14)self.label.setFont(font)self.label.setLineWidth(3)self.label_2 = QLabel(Dialog)self.label_2.setObjectName(u"label_2")self.label_2.setGeometry(QRect(230, 180, 71, 21))self.label_2.setFont(font)self.retranslateUi(Dialog)self.buttonBox.accepted.connect(Dialog.objectName)self.buttonBox.rejected.connect(Dialog.objectName)self.buttonBox.clicked.connect(self.buttonClicked)QMetaObject.connectSlotsByName(Dialog)# setupUidef buttonClicked(self,button):role = self.buttonBox.standardButton(button)if role == QDialogButtonBox.StandardButton.Ok:print("Save clicked")elif role == QDialogButtonBox.StandardButton.Cancel:print("Cancel clicked")def retranslateUi(self, Dialog):Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"Dialog\u6d4b\u8bd5", None))
#if QT_CONFIG(tooltip)self.buttonBox.setToolTip(QCoreApplication.translate("Dialog", u"\u6309\u786e\u5b9a", None))
#endif // QT_CONFIG(tooltip)self.label.setText(QCoreApplication.translate("Dialog", u"\u59d3\u540d", None))self.label_2.setText(QCoreApplication.translate("Dialog", u"\u5bc6\u7801", None))# retranslateUi

simply2.py 引用 simply.py

# -*- coding: utf-8 -*-
# 版权所有 2024 涂聚文有限公司
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:pip install pyqt6
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2023.1 python 3.11
# os        : windows 10
# database  : mysql 9.0 sql server 2019, poostgreSQL 17.0
# Datetime  : 2024/12/7 23:37
# User      : geovindu
# Product   : PyCharm
# Project   : Pysimple
# File      : simply2.py
# explain   : 学习import sys
from PySide6.QtWidgets import QApplication,QWidget
from simple import Ui_Dialogclass Windows(Ui_Dialog,QWidget):""""""def __init__(self):""""""super().__init__()self.setupUi(self)if __name__ == '__main__':app=QApplication(sys.argv)win=Windows()win.show()m=app.exec()sys.exit(m)

测试运行结果:

http://www.lryc.cn/news/526440.html

相关文章:

  • 蓝桥杯LQ1044 求完数
  • 消息队列篇--通信协议篇--TCP和UDP(3次握手和4次挥手,与Socket和webSocket的概念区别等)
  • YOLOv9改进,YOLOv9检测头融合ASFF(自适应空间特征融合),全网首发
  • Elastic Agent 对 Kafka 的新输出:数据收集和流式传输的无限可能性
  • 论文速读|Is Cosine-Similarity of Embeddings Really About Similarity?WWW24
  • Midjourney中的强变化、弱变化、局部重绘的本质区别以及其有多逆天的功能
  • 基于 Node.js 的天气查询系统实现(附源码)
  • 时序数据库的使用场景
  • 计算机的错误计算(二百二十二)
  • ThinkPHP 8模型与数据的插入、更新、删除
  • c语言函数(详解)
  • 为AI聊天工具添加一个知识系统 之70 详细设计 之11 维度运动控制的应用:上下文受控的自然语言
  • ios打包:uuid与udid
  • 数组,对象解构,forEach方法,filter方法
  • PSPNet
  • 论文阅读的附录(七):Understanding Diffusion Models: A Unified Perspective(二):公式46的推导
  • BGP分解实验·12——配置路由反射器
  • PCIe 个人理解专栏——【2】LTSSM(Link Training and Status State Machine)
  • cmake 编译QT之JKQtPlotter-4.0.3
  • 【C】memory 详解
  • Python 爬虫 - Selenium 框架
  • mysql的having语句
  • 华为数据之道-读书笔记
  • CDN、源站与边缘网络
  • 工业相机 SDK 二次开发-Sherlock插件
  • FlinkSql使用中rank/dense_rank函数报错空指针
  • VS C++ 配置OPENCV环境
  • 【SpringSecurity】基本开发流程
  • Redis实战(黑马点评)——关于缓存(缓存更新策略、缓存穿透、缓存雪崩、缓存击穿、Redis工具)
  • ChatGPT从数据分析到内容写作建议相关的46个提示词分享!