无法启动设计的 pyQt 应用程序 [英] Can't start designed pyQt application
问题描述
我刚刚在 pyQt Designer 5 中设计了我的应用程序,将 main.ui 生成为 main.py,将 assets.qrc 生成为 assets_rc.py.没有错误,当我现在从终端运行 main.py 时,什么也没有发生.我错过了一步吗?我现在应该编辑我的 main.py 文件吗?
I have just designed my application inside pyQt Designer 5, generated my main.ui to main.py and my assets.qrc to assets_rc.py. No errors, when I now run main.py from my terminal nothing happends. Have I missed a step? Am I supposed to edit my main.py file now?
干杯!
Python 3.3.0pyQT 5
Python 3.3.0 pyQT 5
推荐答案
这适用于 PyQt4
,但应该与 PyQt5
相同.
This is for PyQt4
, but should be the same for PyQt5
.
假设您的用户界面名为mainwindow.ui".使用 pyuic4 将其编译为mainWindowUi.py"(或其他任何内容,只需保留名称即可).
Let's say your ui is called "mainwindow.ui". Compile this with pyuic4 into "mainWindowUi.py" (or whatever, just stick to the name).
现在创建一个包含或多或少此内容的文件mainWindow.py":
Now create a file "mainWindow.py" with more or less this content:
from PyQt4 import QtGui
from mainWindowUi import Ui_MainWindow #same name as appears in mainWindowUi.py
class MainWindow (QtGui.QMainWindow): #Or wherever you are inheriting from
def __init__ (self, parent = None):
super (MainWindow, self).__init__ ()
self.ui = Ui_MainWindow () #same name as appears in mainWindowUi.py
self.ui.setupUi (self)
#implement slots and signals and other funny things
现在创建一个包含或多或少此内容的文件program.py":
Now create a file "program.py" with more or less this content:
#! /usr/bin/python3.3
import sys
from PyQt4 import QtGui
from mainWindow import MainWindow
def main():
app = QtGui.QApplication (sys.argv)
m = MainWindow ()
m.show ()
sys.exit (app.exec_ () )
if __name__ == '__main__':
main ()
运行 program.py
文件.这或多或少是 Qt 应用程序的骨架.
Run the program.py
file. This is more or less the skeleton of a Qt application.
这篇关于无法启动设计的 pyQt 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!