• <bdo id='8TMYu'></bdo><ul id='8TMYu'></ul>
    <i id='8TMYu'><tr id='8TMYu'><dt id='8TMYu'><q id='8TMYu'><span id='8TMYu'><b id='8TMYu'><form id='8TMYu'><ins id='8TMYu'></ins><ul id='8TMYu'></ul><sub id='8TMYu'></sub></form><legend id='8TMYu'></legend><bdo id='8TMYu'><pre id='8TMYu'><center id='8TMYu'></center></pre></bdo></b><th id='8TMYu'></th></span></q></dt></tr></i><div id='8TMYu'><tfoot id='8TMYu'></tfoot><dl id='8TMYu'><fieldset id='8TMYu'></fieldset></dl></div>
      <legend id='8TMYu'><style id='8TMYu'><dir id='8TMYu'><q id='8TMYu'></q></dir></style></legend>

      1. <tfoot id='8TMYu'></tfoot>
      2. <small id='8TMYu'></small><noframes id='8TMYu'>

        使用 QTdesigner 创建的 PyQt5 程序从终端打开时不显

        时间:2023-08-04

          <tbody id='wwxoK'></tbody>
      3. <legend id='wwxoK'><style id='wwxoK'><dir id='wwxoK'><q id='wwxoK'></q></dir></style></legend>

      4. <tfoot id='wwxoK'></tfoot>
          <bdo id='wwxoK'></bdo><ul id='wwxoK'></ul>
          <i id='wwxoK'><tr id='wwxoK'><dt id='wwxoK'><q id='wwxoK'><span id='wwxoK'><b id='wwxoK'><form id='wwxoK'><ins id='wwxoK'></ins><ul id='wwxoK'></ul><sub id='wwxoK'></sub></form><legend id='wwxoK'></legend><bdo id='wwxoK'><pre id='wwxoK'><center id='wwxoK'></center></pre></bdo></b><th id='wwxoK'></th></span></q></dt></tr></i><div id='wwxoK'><tfoot id='wwxoK'></tfoot><dl id='wwxoK'><fieldset id='wwxoK'></fieldset></dl></div>
        • <small id='wwxoK'></small><noframes id='wwxoK'>

                  本文介绍了使用 QTdesigner 创建的 PyQt5 程序从终端打开时不显示任何窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 QT Designer 没有任何问题,但是今天我开始了全新的 ubuntu 18.04 安装,但是这次当我从终端运行 PyQt5 程序时,它们没有显示任何窗口,从 atom-runner 运行时出现同样的问题(它没有甚至显示任何错误)

                  I was working with QT Designer with no issues but today i started a fresh ubuntu 18.04 install, but this time when i run the PyQt5 programs from terminal they doesnt show any windows, same issue when running from atom-runner (It doesnt even show any error)

                  我将 .ui 文件从 Qt Designer 保存后直接使用 pyuic5 导出为 .py,尝试了一个简单的空白窗口和同样的问题

                  I exported the .ui files into .py using pyuic5 directly after saving them from Qt Designer, tried a simple blank window and same problem

                  知道如何解决这个问题吗?

                  Any idea how can i fix this?

                  这是一个代码示例,一个应该显示但由于某种原因它不会显示的简单窗口

                  This is an example of the code, a simple window that should show but for some reason it wont

                       # -*- coding: utf-8 -*-
                  
                  # Form implementation generated from reading ui file 'label.ui'
                  #
                  # Created by: PyQt5 UI code generator 5.11.3
                  #
                  # WARNING! All changes made in this file will be lost!
                  
                  from PyQt5 import QtCore, QtGui, QtWidgets
                  
                  class Ui_MainWindow(object):
                      def setupUi(self, MainWindow):
                          MainWindow.setObjectName("MainWindow")
                          MainWindow.resize(315, 142)
                          self.centralwidget = QtWidgets.QWidget(MainWindow)
                          self.centralwidget.setObjectName("centralwidget")
                          self.label = QtWidgets.QLabel(self.centralwidget)
                          self.label.setGeometry(QtCore.QRect(20, 20, 371, 111))
                          font = QtGui.QFont()
                          font.setPointSize(45)
                          self.label.setFont(font)
                          self.label.setObjectName("label")
                          MainWindow.setCentralWidget(self.centralwidget)
                          self.statusbar = QtWidgets.QStatusBar(MainWindow)
                          self.statusbar.setObjectName("statusbar")
                          MainWindow.setStatusBar(self.statusbar)
                  
                          self.retranslateUi(MainWindow)
                          QtCore.QMetaObject.connectSlotsByName(MainWindow)
                  
                      def retranslateUi(self, MainWindow):
                          _translate = QtCore.QCoreApplication.translate
                          MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
                          self.label.setText(_translate("MainWindow", "DA LABEL"))
                  

                  推荐答案

                  要生成可以使用 pyuic 显示窗口的代码,您必须使用 -x 选项:

                  To generate a code that can show a window using pyuic you must use the -x option:

                  pyuic5 input.ui -o output.py -x
                  

                  使用 -x 的上一条命令将以下代码添加到文件末尾:

                  The previous command using the -x adds the following code to the end of the file:

                  if __name__ == "__main__":
                      import sys
                      app = QtWidgets.QApplication(sys.argv)
                      MainWindow = QtWidgets.QMainWindow()
                      ui = Ui_MainWindow()
                      ui.setupUi(MainWindow)
                      MainWindow.show()
                      sys.exit(app.exec_())
                  

                  这篇关于使用 QTdesigner 创建的 PyQt5 程序从终端打开时不显示任何窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:显示来自其他文件的 Matplotlib 图 下一篇:QHBoxLayout 以不同的顺序添加小部件

                  相关文章

                  最新文章

                  • <bdo id='cGgno'></bdo><ul id='cGgno'></ul>

                  <i id='cGgno'><tr id='cGgno'><dt id='cGgno'><q id='cGgno'><span id='cGgno'><b id='cGgno'><form id='cGgno'><ins id='cGgno'></ins><ul id='cGgno'></ul><sub id='cGgno'></sub></form><legend id='cGgno'></legend><bdo id='cGgno'><pre id='cGgno'><center id='cGgno'></center></pre></bdo></b><th id='cGgno'></th></span></q></dt></tr></i><div id='cGgno'><tfoot id='cGgno'></tfoot><dl id='cGgno'><fieldset id='cGgno'></fieldset></dl></div>

                  1. <tfoot id='cGgno'></tfoot>
                  2. <small id='cGgno'></small><noframes id='cGgno'>

                    <legend id='cGgno'><style id='cGgno'><dir id='cGgno'><q id='cGgno'></q></dir></style></legend>