- 安裝 python
- 安裝 vscode
- 安裝 PyQt5 → pip install PyQt5
- 安裝 PyQt5-tools → pip install PyQt5-tools
- 設定 vscode 與 PyQt5
- 使用 PyQT5 設計產生視窗
安裝python
官網:https://www.python.org/
設定系統 path
設定系統 path
安裝vscode
安裝 PyQt5 PyQt5-tools
pip install PyQt5
pip install PyQt5-tools
設定系統 path
設定系統 path
設定 vscode 與 PyQt5
設定 PYQT Integration
點選設定
在 cmd 視窗輸入 designer 啟動 PyQT5
設計視窗畫面
設計 test.ui 儲存到指定的資料匣,使用 vscode 進行轉換並產生,右鍵選 PYQT:Compile Form
產生 Ui_test.py 打開執行
執行成功
# -*- coding: utf-8 -*-
#
# Form implementation generated from reading ui file 'd:\python-training\project\test.ui'
#
# Created by: PyQt5 UI code generator 5.14.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setGeometry(QtCore.QRect(30, 240, 341, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(60, 80, 91, 41))
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setPointSize(14)
self.label.setFont(font)
self.label.setObjectName("label")
self.textEdit = QtWidgets.QTextEdit(Dialog)
self.textEdit.setGeometry(QtCore.QRect(160, 90, 131, 31))
self.textEdit.setObjectName("textEdit")
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(Dialog.accept)
self.buttonBox.rejected.connect(Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label.setText(_translate("Dialog", "輸入姓名"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
沒有留言:
張貼留言