Closed Liberty0 closed 4 years ago
建立 module
main.py
mainForm
| __init__.py
ui
| UI design.ui
(PyQt 存檔)
what's in main.py
from PyQt5 import QtWidgets
from mainForm import MainUi # 讀入Main Window
import sys
if __name__ == "__main__":
def run_app():
app = QtWidgets.QApplication(sys.argv)
window = MainUi()
window.show()
app.exec_()
run_app()
what's in __init__.py
from PyQt5 import QtWidgets, uic
import os
path = os.getcwd()
qtCreatorFile = path + os.sep + "ui" + os.sep + "UI design.ui" # 設計好的ui檔案路徑
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile) # 讀入用Qt Designer設計的GUI layout
class MainUi(QtWidgets.QMainWindow, Ui_MainWindow): # Python的多重繼承 MainUi 繼承自兩個類別
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
ca07a4ad099d731ad7797b52d205e69a80c7b04f
gui with plot aixs built in testing2
ui_import.py
mplwidget.py
iu
| mainwindow.ui
ref: https://yapayzekalabs.blogspot.com/2018/11/pyqt5-gui-qt-designer-matplotlib.html
def __init__(self,*args,**kwargs):
self.textEdit.textChanged.connect(self.varinput)
def varinput(self):
self.label.setText(self.textEdit.toPlainText())
97e4ba338158b5a72f2ce28b5203a38608dcaeee
53273bb10fcf9759740e654797647b4d90ab7529
安裝pyqt
pip install pyqt5
at Anaconda promptERROR: spyder 3.3.6 has requirement pyqt5<5.13; python_version >= "3", but you'll have pyqt5 5.13.0 which is incompatible.
Spyder require lower version PyQtpip install pyqt5==5.11.3
pip install pyqtwebengine
無法啟動spyder ↓ 在安裝Anaconda時,已經連Qt一起安裝了 路徑
C:\Users\User\anaconda3\Library\bin\designer.exe