简体   繁体   English

Python 3 PyQT(使用设计器),开始出现问题

[英]Python 3 PyQT (Using Designer), having issues starting

I am trying to branch out into developing a program with a GUI, and since I like KDE a lot I figured I would give PyQT a shot. 我正在尝试扩展到使用GUI开发程序,并且由于我非常喜欢KDE,所以我认为我可以尝试一下PyQT。 Here's an example of what I have so far (no logic just yet, I wanted to see if I could get the UI to display). 这是到目前为止我所拥有的示例(目前还没有逻辑,我想看看是否可以显示UI)。

Here is the UI file named at.ui 这是名为at.ui的UI文件

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>410</width>
    <height>322</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QTabWidget" name="tabWidget">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>10</y>
      <width>261</width>
      <height>271</height>
     </rect>
    </property>
    <property name="tabPosition">
     <enum>QTabWidget::North</enum>
    </property>
    <property name="tabShape">
     <enum>QTabWidget::Rounded</enum>
    </property>
    <property name="currentIndex">
     <number>2</number>
    </property>
    <property name="tabsClosable">
     <bool>false</bool>
    </property>
    <widget class="QWidget" name="tab">
     <attribute name="title">
      <string>Information</string>
     </attribute>
     <widget class="QWidget" name="formLayoutWidget">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>251</width>
        <height>111</height>
       </rect>
      </property>
      <layout class="QFormLayout" name="formLayout">
       <item row="0" column="0">
        <widget class="QLabel" name="jobNameLabel">
         <property name="text">
          <string>Job Name</string>
         </property>
        </widget>
       </item>
       <item row="0" column="1">
        <widget class="QLineEdit" name="jobNameLineEdit"/>
       </item>
       <item row="1" column="0">
        <widget class="QLabel" name="inputDirectoryLabel">
         <property name="text">
          <string>Input Directory</string>
         </property>
        </widget>
       </item>
       <item row="1" column="1">
        <widget class="QLineEdit" name="inputDirectoryLineEdit"/>
       </item>
       <item row="2" column="0">
        <widget class="QLabel" name="albumNameLabel">
         <property name="text">
          <string>Album Name</string>
         </property>
        </widget>
       </item>
       <item row="2" column="1">
        <widget class="QLineEdit" name="albumNameLineEdit"/>
       </item>
       <item row="3" column="0">
        <widget class="QLabel" name="scalingAmountLabel">
         <property name="text">
          <string>Scaling Amount</string>
         </property>
        </widget>
       </item>
       <item row="3" column="1">
        <widget class="QComboBox" name="scalingAmountComboBox">
         <property name="sizePolicy">
          <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
         <item>
          <property name="text">
           <string>10% of Original</string>
          </property>
         </item>
         <item>
          <property name="text">
           <string>20% of Original</string>
          </property>
         </item>
         <item>
          <property name="text">
           <string>30% of Original</string>
          </property>
         </item>
         <item>
          <property name="text">
           <string>40% of Original</string>
          </property>
         </item>
         <item>
          <property name="text">
           <string>50% of Original</string>
          </property>
         </item>
         <item>
          <property name="text">
           <string>60% of Original</string>
          </property>
         </item>
         <item>
          <property name="text">
           <string>70% of Original</string>
          </property>
         </item>
         <item>
          <property name="text">
           <string>80% of Original</string>
          </property>
         </item>
         <item>
          <property name="text">
           <string>90% of Original</string>
          </property>
         </item>
         <item>
          <property name="text">
           <string>100% of Original</string>
          </property>
         </item>
        </widget>
       </item>
      </layout>
     </widget>
     <widget class="QTextEdit" name="textEdit">
      <property name="geometry">
       <rect>
        <x>3</x>
        <y>130</y>
        <width>251</width>
        <height>111</height>
       </rect>
      </property>
     </widget>
     <widget class="QLabel" name="label_3">
      <property name="geometry">
       <rect>
        <x>10</x>
        <y>110</y>
        <width>53</width>
        <height>14</height>
       </rect>
      </property>
      <property name="text">
       <string>Notes</string>
      </property>
     </widget>
    </widget>
    <widget class="QWidget" name="tab_2">
     <attribute name="title">
      <string>Manual</string>
     </attribute>
     <widget class="QPushButton" name="pushButton_5">
      <property name="geometry">
       <rect>
        <x>30</x>
        <y>120</y>
        <width>181</width>
        <height>25</height>
       </rect>
      </property>
      <property name="text">
       <string>Step 1 (Copy Images)</string>
      </property>
     </widget>
     <widget class="QPushButton" name="pushButton_4">
      <property name="geometry">
       <rect>
        <x>30</x>
        <y>150</y>
        <width>181</width>
        <height>25</height>
       </rect>
      </property>
      <property name="text">
       <string>Step 2 (Resize Images)</string>
      </property>
     </widget>
     <widget class="QPushButton" name="pushButton_3">
      <property name="geometry">
       <rect>
        <x>30</x>
        <y>180</y>
        <width>181</width>
        <height>25</height>
       </rect>
      </property>
      <property name="text">
       <string>Step 3 (Upload Images)</string>
      </property>
     </widget>
     <widget class="QPushButton" name="pushButton_2">
      <property name="geometry">
       <rect>
        <x>30</x>
        <y>210</y>
        <width>181</width>
        <height>25</height>
       </rect>
      </property>
      <property name="text">
       <string>Step 4 (Manage Album)</string>
      </property>
     </widget>
     <widget class="QLabel" name="label_2">
      <property name="geometry">
       <rect>
        <x>10</x>
        <y>10</y>
        <width>241</width>
        <height>61</height>
       </rect>
      </property>
      <property name="frameShape">
       <enum>QFrame::NoFrame</enum>
      </property>
      <property name="text">
       <string>This is the manual method of uploading your images.  Complete all four steps and you'll be done!</string>
      </property>
      <property name="wordWrap">
       <bool>true</bool>
      </property>
     </widget>
    </widget>
    <widget class="QWidget" name="tab_3">
     <attribute name="title">
      <string>Automatic</string>
     </attribute>
     <widget class="QPushButton" name="pushButton_6">
      <property name="geometry">
       <rect>
        <x>10</x>
        <y>170</y>
        <width>231</width>
        <height>61</height>
       </rect>
      </property>
      <property name="text">
       <string>Express Mode</string>
      </property>
     </widget>
     <widget class="QLabel" name="label">
      <property name="geometry">
       <rect>
        <x>10</x>
        <y>10</y>
        <width>241</width>
        <height>61</height>
       </rect>
      </property>
      <property name="frameShape">
       <enum>QFrame::NoFrame</enum>
      </property>
      <property name="text">
       <string>This is the automatic method of uploading your images.  Clicking the 'Express Mode' button will finish the entire process for you.</string>
      </property>
      <property name="wordWrap">
       <bool>true</bool>
      </property>
     </widget>
    </widget>
   </widget>
   <widget class="QPushButton" name="pushButton">
    <property name="geometry">
     <rect>
      <x>270</x>
      <y>250</y>
      <width>131</width>
      <height>25</height>
     </rect>
    </property>
    <property name="text">
     <string>Exit</string>
    </property>
   </widget>
   <widget class="QLabel" name="label_4">
    <property name="geometry">
     <rect>
      <x>270</x>
      <y>0</y>
      <width>131</width>
      <height>81</height>
     </rect>
    </property>
    <property name="text">
     <string>First, fill out the fields in the Information tab.  Next, choose either Manual or Automatic processing.</string>
    </property>
    <property name="wordWrap">
     <bool>true</bool>
    </property>
   </widget>
   <widget class="QLabel" name="label_5">
    <property name="geometry">
     <rect>
      <x>270</x>
      <y>80</y>
      <width>131</width>
      <height>101</height>
     </rect>
    </property>
    <property name="text">
     <string>There are additional tools and options available in the menubar.  If you need any assistance, check out the Help menu for more information!</string>
    </property>
    <property name="wordWrap">
     <bool>true</bool>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_7">
    <property name="geometry">
     <rect>
      <x>270</x>
      <y>220</y>
      <width>131</width>
      <height>25</height>
     </rect>
    </property>
    <property name="text">
     <string>Export</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_8">
    <property name="geometry">
     <rect>
      <x>270</x>
      <y>190</y>
      <width>131</width>
      <height>25</height>
     </rect>
    </property>
    <property name="text">
     <string>Import</string>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>410</width>
     <height>21</height>
    </rect>
   </property>
   <widget class="QMenu" name="menuFileFile">
    <property name="title">
     <string>File</string>
    </property>
   </widget>
   <widget class="QMenu" name="menuTools">
    <property name="title">
     <string>Tools</string>
    </property>
   </widget>
   <widget class="QMenu" name="menuHelp">
    <property name="title">
     <string>Help</string>
    </property>
   </widget>
   <addaction name="menuFileFile"/>
   <addaction name="menuTools"/>
   <addaction name="menuHelp"/>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>

I used pyuic to compile it into Python code and got the following, named at_auto.py: 我使用pyuic将其编译为Python代码,并获得了名为at_auto.py的以下内容:

#!/usr/bin/python3
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'QT/at.ui'
#
# Created: Thu Feb  9 14:05:42 2012
#      by: PyQt4 UI code generator 4.9
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(410, 322)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.tabWidget = QtGui.QTabWidget(self.centralwidget)
        self.tabWidget.setGeometry(QtCore.QRect(0, 10, 261, 271))
        self.tabWidget.setTabPosition(QtGui.QTabWidget.North)
        self.tabWidget.setTabShape(QtGui.QTabWidget.Rounded)
        self.tabWidget.setTabsClosable(False)
        self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
        self.tab = QtGui.QWidget()
        self.tab.setObjectName(_fromUtf8("tab"))
        self.formLayoutWidget = QtGui.QWidget(self.tab)
        self.formLayoutWidget.setGeometry(QtCore.QRect(0, 0, 251, 111))
        self.formLayoutWidget.setObjectName(_fromUtf8("formLayoutWidget"))
        self.formLayout = QtGui.QFormLayout(self.formLayoutWidget)
        self.formLayout.setMargin(0)
        self.formLayout.setObjectName(_fromUtf8("formLayout"))
        self.jobNameLabel = QtGui.QLabel(self.formLayoutWidget)
        self.jobNameLabel.setObjectName(_fromUtf8("jobNameLabel"))
        self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.jobNameLabel)
        self.jobNameLineEdit = QtGui.QLineEdit(self.formLayoutWidget)
        self.jobNameLineEdit.setObjectName(_fromUtf8("jobNameLineEdit"))
        self.formLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.jobNameLineEdit)
        self.inputDirectoryLabel = QtGui.QLabel(self.formLayoutWidget)
        self.inputDirectoryLabel.setObjectName(_fromUtf8("inputDirectoryLabel"))
        self.formLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.inputDirectoryLabel)
        self.inputDirectoryLineEdit = QtGui.QLineEdit(self.formLayoutWidget)
        self.inputDirectoryLineEdit.setObjectName(_fromUtf8("inputDirectoryLineEdit"))
        self.formLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.inputDirectoryLineEdit)
        self.albumNameLabel = QtGui.QLabel(self.formLayoutWidget)
        self.albumNameLabel.setObjectName(_fromUtf8("albumNameLabel"))
        self.formLayout.setWidget(2, QtGui.QFormLayout.LabelRole, self.albumNameLabel)
        self.albumNameLineEdit = QtGui.QLineEdit(self.formLayoutWidget)
        self.albumNameLineEdit.setObjectName(_fromUtf8("albumNameLineEdit"))
        self.formLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.albumNameLineEdit)
        self.scalingAmountLabel = QtGui.QLabel(self.formLayoutWidget)
        self.scalingAmountLabel.setObjectName(_fromUtf8("scalingAmountLabel"))
        self.formLayout.setWidget(3, QtGui.QFormLayout.LabelRole, self.scalingAmountLabel)
        self.scalingAmountComboBox = QtGui.QComboBox(self.formLayoutWidget)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.scalingAmountComboBox.sizePolicy().hasHeightForWidth())
        self.scalingAmountComboBox.setSizePolicy(sizePolicy)
        self.scalingAmountComboBox.setObjectName(_fromUtf8("scalingAmountComboBox"))
        self.scalingAmountComboBox.addItem(_fromUtf8(""))
        self.scalingAmountComboBox.addItem(_fromUtf8(""))
        self.scalingAmountComboBox.addItem(_fromUtf8(""))
        self.scalingAmountComboBox.addItem(_fromUtf8(""))
        self.scalingAmountComboBox.addItem(_fromUtf8(""))
        self.scalingAmountComboBox.addItem(_fromUtf8(""))
        self.scalingAmountComboBox.addItem(_fromUtf8(""))
        self.scalingAmountComboBox.addItem(_fromUtf8(""))
        self.scalingAmountComboBox.addItem(_fromUtf8(""))
        self.scalingAmountComboBox.addItem(_fromUtf8(""))
        self.formLayout.setWidget(3, QtGui.QFormLayout.FieldRole, self.scalingAmountComboBox)
        self.textEdit = QtGui.QTextEdit(self.tab)
        self.textEdit.setGeometry(QtCore.QRect(3, 130, 251, 111))
        self.textEdit.setObjectName(_fromUtf8("textEdit"))
        self.label_3 = QtGui.QLabel(self.tab)
        self.label_3.setGeometry(QtCore.QRect(10, 110, 53, 14))
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.tabWidget.addTab(self.tab, _fromUtf8(""))
        self.tab_2 = QtGui.QWidget()
        self.tab_2.setObjectName(_fromUtf8("tab_2"))
        self.pushButton_5 = QtGui.QPushButton(self.tab_2)
        self.pushButton_5.setGeometry(QtCore.QRect(30, 120, 181, 25))
        self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
        self.pushButton_4 = QtGui.QPushButton(self.tab_2)
        self.pushButton_4.setGeometry(QtCore.QRect(30, 150, 181, 25))
        self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
        self.pushButton_3 = QtGui.QPushButton(self.tab_2)
        self.pushButton_3.setGeometry(QtCore.QRect(30, 180, 181, 25))
        self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
        self.pushButton_2 = QtGui.QPushButton(self.tab_2)
        self.pushButton_2.setGeometry(QtCore.QRect(30, 210, 181, 25))
        self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
        self.label_2 = QtGui.QLabel(self.tab_2)
        self.label_2.setGeometry(QtCore.QRect(10, 10, 241, 61))
        self.label_2.setFrameShape(QtGui.QFrame.NoFrame)
        self.label_2.setWordWrap(True)
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.tabWidget.addTab(self.tab_2, _fromUtf8(""))
        self.tab_3 = QtGui.QWidget()
        self.tab_3.setObjectName(_fromUtf8("tab_3"))
        self.pushButton_6 = QtGui.QPushButton(self.tab_3)
        self.pushButton_6.setGeometry(QtCore.QRect(10, 170, 231, 61))
        self.pushButton_6.setObjectName(_fromUtf8("pushButton_6"))
        self.label = QtGui.QLabel(self.tab_3)
        self.label.setGeometry(QtCore.QRect(10, 10, 241, 61))
        self.label.setFrameShape(QtGui.QFrame.NoFrame)
        self.label.setWordWrap(True)
        self.label.setObjectName(_fromUtf8("label"))
        self.tabWidget.addTab(self.tab_3, _fromUtf8(""))
        self.pushButton = QtGui.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(270, 250, 131, 25))
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.label_4 = QtGui.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(270, 0, 131, 81))
        self.label_4.setWordWrap(True)
        self.label_4.setObjectName(_fromUtf8("label_4"))
        self.label_5 = QtGui.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(270, 80, 131, 101))
        self.label_5.setWordWrap(True)
        self.label_5.setObjectName(_fromUtf8("label_5"))
        self.pushButton_7 = QtGui.QPushButton(self.centralwidget)
        self.pushButton_7.setGeometry(QtCore.QRect(270, 220, 131, 25))
        self.pushButton_7.setObjectName(_fromUtf8("pushButton_7"))
        self.pushButton_8 = QtGui.QPushButton(self.centralwidget)
        self.pushButton_8.setGeometry(QtCore.QRect(270, 190, 131, 25))
        self.pushButton_8.setObjectName(_fromUtf8("pushButton_8"))
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 410, 21))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        self.menuFileFile = QtGui.QMenu(self.menubar)
        self.menuFileFile.setObjectName(_fromUtf8("menuFileFile"))
        self.menuTools = QtGui.QMenu(self.menubar)
        self.menuTools.setObjectName(_fromUtf8("menuTools"))
        self.menuHelp = QtGui.QMenu(self.menubar)
        self.menuHelp.setObjectName(_fromUtf8("menuHelp"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)
        self.menubar.addAction(self.menuFileFile.menuAction())
        self.menubar.addAction(self.menuTools.menuAction())
        self.menubar.addAction(self.menuHelp.menuAction())

        self.retranslateUi(MainWindow)
        self.tabWidget.setCurrentIndex(2)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
        self.jobNameLabel.setText(QtGui.QApplication.translate("MainWindow", "Job Name", None, QtGui.QApplication.UnicodeUTF8))
        self.inputDirectoryLabel.setText(QtGui.QApplication.translate("MainWindow", "Input Directory", None, QtGui.QApplication.UnicodeUTF8))
        self.albumNameLabel.setText(QtGui.QApplication.translate("MainWindow", "Album Name", None, QtGui.QApplication.UnicodeUTF8))
        self.scalingAmountLabel.setText(QtGui.QApplication.translate("MainWindow", "Scaling Amount", None, QtGui.QApplication.UnicodeUTF8))
        self.scalingAmountComboBox.setItemText(0, QtGui.QApplication.translate("MainWindow", "10% of Original", None, QtGui.QApplication.UnicodeUTF8))
        self.scalingAmountComboBox.setItemText(1, QtGui.QApplication.translate("MainWindow", "20% of Original", None, QtGui.QApplication.UnicodeUTF8))
        self.scalingAmountComboBox.setItemText(2, QtGui.QApplication.translate("MainWindow", "30% of Original", None, QtGui.QApplication.UnicodeUTF8))
        self.scalingAmountComboBox.setItemText(3, QtGui.QApplication.translate("MainWindow", "40% of Original", None, QtGui.QApplication.UnicodeUTF8))
        self.scalingAmountComboBox.setItemText(4, QtGui.QApplication.translate("MainWindow", "50% of Original", None, QtGui.QApplication.UnicodeUTF8))
        self.scalingAmountComboBox.setItemText(5, QtGui.QApplication.translate("MainWindow", "60% of Original", None, QtGui.QApplication.UnicodeUTF8))
        self.scalingAmountComboBox.setItemText(6, QtGui.QApplication.translate("MainWindow", "70% of Original", None, QtGui.QApplication.UnicodeUTF8))
        self.scalingAmountComboBox.setItemText(7, QtGui.QApplication.translate("MainWindow", "80% of Original", None, QtGui.QApplication.UnicodeUTF8))
        self.scalingAmountComboBox.setItemText(8, QtGui.QApplication.translate("MainWindow", "90% of Original", None, QtGui.QApplication.UnicodeUTF8))
        self.scalingAmountComboBox.setItemText(9, QtGui.QApplication.translate("MainWindow", "100% of Original", None, QtGui.QApplication.UnicodeUTF8))
        self.label_3.setText(QtGui.QApplication.translate("MainWindow", "Notes", None, QtGui.QApplication.UnicodeUTF8))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), QtGui.QApplication.translate("MainWindow", "Information", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_5.setText(QtGui.QApplication.translate("MainWindow", "Step 1 (Copy Images)", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_4.setText(QtGui.QApplication.translate("MainWindow", "Step 2 (Resize Images)", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_3.setText(QtGui.QApplication.translate("MainWindow", "Step 3 (Upload Images)", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_2.setText(QtGui.QApplication.translate("MainWindow", "Step 4 (Manage Album)", None, QtGui.QApplication.UnicodeUTF8))
        self.label_2.setText(QtGui.QApplication.translate("MainWindow", "This is the manual method of uploading your images.  Complete all four steps and you\'ll be done!", None, QtGui.QApplication.UnicodeUTF8))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), QtGui.QApplication.translate("MainWindow", "Manual", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_6.setText(QtGui.QApplication.translate("MainWindow", "Express Mode", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setText(QtGui.QApplication.translate("MainWindow", "This is the automatic method of uploading your images.  Clicking the \'Express Mode\' button will finish the entire process for you.", None, QtGui.QApplication.UnicodeUTF8))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_3), QtGui.QApplication.translate("MainWindow", "Automatic", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("MainWindow", "Exit", None, QtGui.QApplication.UnicodeUTF8))
        self.label_4.setText(QtGui.QApplication.translate("MainWindow", "First, fill out the fields in the Information tab.  Next, choose either Manual or Automatic processing.", None, QtGui.QApplication.UnicodeUTF8))
        self.label_5.setText(QtGui.QApplication.translate("MainWindow", "There are additional tools and options available in the menubar.  If you need any assistance, check out the Help menu for more information!", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_7.setText(QtGui.QApplication.translate("MainWindow", "Export", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_8.setText(QtGui.QApplication.translate("MainWindow", "Import", None, QtGui.QApplication.UnicodeUTF8))
        self.menuFileFile.setTitle(QtGui.QApplication.translate("MainWindow", "File", None, QtGui.QApplication.UnicodeUTF8))
        self.menuTools.setTitle(QtGui.QApplication.translate("MainWindow", "Tools", None, QtGui.QApplication.UnicodeUTF8))
        self.menuHelp.setTitle(QtGui.QApplication.translate("MainWindow", "Help", None, QtGui.QApplication.UnicodeUTF8))

The Python script to start it is: 启动它的Python脚本是:

#!/usr/bin/python3

from PyQt4 import QtGui, QtCore
import at_auto, os

class at(at_auto):
    def __init__(self):
        at_auto.__init__(self)

if __name__ == '__main__':
    import sys
    a = QtGui.QApplication(sys.argv)
    QtCore.QObject.connect(a, QtCore.SIGNAL('lastWindowClosed()'), a, QtCore.SLOT('quit()'))
    w = at(at_auto.__init__(self))
    a.setMainWindow(w)
    w.show()
    a.exec_loop()

When attempting to run the program, I get the following error: 尝试运行程序时,出现以下错误:

Traceback (most recent call last):
  File "./at.py", line 6, in <module>
    class at(at_auto):
TypeError: module.__init__() takes at most 2 arguments (3 given)

I modified the code in at.py from the following tutorial: 我从以下教程中修改了at.py中的代码:

http://wiki.python.org/moin/JonathanGardnerPyQtTutorial#Using_pyuic http://wiki.python.org/moin/JonathanGardnerPyQtTutorial#Using_pyuic

Thank you so much! 非常感谢!

Firstly: that tutorial you linked to is very out of date (it relates to PyQt3 rather than PyQt4), so I would suggest you have a look here for something more recent. 首先:您链接到的教程已经过时了(它与PyQt3而不是PyQt4有关),所以我建议您在这里查找最新的内容。

But to deal with the issue at hand - it will simplify things somewhat if you start by recompiling the ui using this command: 但是要解决当前的问题-如果使用以下命令重新编译ui,它将使事情有所简化:

pyuic4 -w at.ui > at_auto.py

The -w option will generate an additional GUI class that is much more intuitive to use than the one created by default. -w选项将生成一个附加的GUI类,它比默认创建的GUI类使用起来更加直观。 The name of this class will have the same name as the top-level object created in Qt Designer - in your case, this will be MainWindow . 此类的名称与Qt Designer中创建的顶级对象的名称相同-在您的情况下,该名称为MainWindow

To use it, just import it into your main script, create a subclass, and then show an instance of it, like this: 要使用它,只需将其导入您的main脚本,创建一个子类,然后show它的实例,如下所示:

from PyQt4 import QtGui, QtCore
from at_auto import MainWindow

class Window(MainWindow):
    def __init__(self):
        MainWindow.__init__(self)
        # do other initialization stuff here...

if __name__ == '__main__':

    import sys
    app = QtGui.QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pyqt5设计师和Python 3.5 - Pyqt5 designer and Python 3.5 Python计算器-使用3号出现问题 - Python calculator - Having issues using 3 number 在python中使用sort函数,出现问题 - Using the sort function in python, having issues with it 如何使用pyqt5将python代码转换为gui? (禁止使用Qt Designer或其他应用程序,我必须自己编写代码) - how to transform a python code to a gui using pyqt5? (using qt designer or other app are prohibited, i have to code it my self) 如何将小部件添加到已经使用 Qt 设计器布局“剧透”的 PyQt5 我想出了如何在 python 中关闭和打开另一个 window - How to add Widgets to a PyQt5 already using a Qt designer layout "Spoiler" I have figured how to close and open another window in python 使用自己的字母字符串(python)解密密文有问题 - Having issues Decrpyting ciphertext using own alphabet string (python) 使用 Python 求解一对非线性方程时遇到问题 - Having issues solving pair of nonlinear equations using Python 在由 Qt Designer (PyQt5) 生成的 html 中插入 Python 变量 - Inserting a Python variable inside html generated by Qt Designer (PyQt5) 如何使用pyqt、qt设计器弹出新窗口 - How to pop up new window using pyqt, qt designer Python 中的 shell 命令有问题 - Having issues with a shell command in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM