我用 PyQt GUI 做了一个简单的程序,并编译了 '.ui' 文件。
# Form implementation generated from reading ui file 'main.ui'
#
# Created by: PyQt5 UI code generator 5.6
#
# 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.setEnabled(True)
MainWindow.resize(441, 255)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
MainWindow.setAutoFillBackground(False)
MainWindow.setTabShape(QtWidgets.QTabWidget.Rounded)
self.frame = QtWidgets.QWidget(MainWindow)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth())
self.frame.setSizePolicy(sizePolicy)
self.frame.setObjectName("frame")
self.tab = QtWidgets.QTabWidget(self.frame)
self.tab.setGeometry(QtCore.QRect(10, 10, 421, 201))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.tab.sizePolicy().hasHeightForWidth())
self.tab.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("UltraLight")
font.setPointSize(10)
self.tab.setFont(font)
self.tab.setTabShape(QtWidgets.QTabWidget.Triangular)
self.tab.setMovable(False)
self.tab.setTabBarAutoHide(False)
self.tab.setObjectName("tab")
self.tabOption = QtWidgets.QWidget()
self.tabOption.setObjectName("tabOption")
self.profileList = QtWidgets.QComboBox(self.tabOption)
self.profileList.setGeometry(QtCore.QRect(60, 10, 121, 20))
font = QtGui.QFont()
font.setFamily("UltraLight")
font.setPointSize(10)
self.profileList.setFont(font)
self.profileList.setObjectName("profileList")
self.ramInput = QtWidgets.QLineEdit(self.tabOption)
self.ramInput.setGeometry(QtCore.QRect(50, 40, 81, 20))
self.ramInput.setObjectName("ramInput")
self.ramLabel = QtWidgets.QLabel(self.tabOption)
self.ramLabel.setGeometry(QtCore.QRect(10, 40, 31, 21))
font = QtGui.QFont()
font.setFamily("나눔바른고딕 UltraLight")
font.setPointSize(10)
self.ramLabel.setFont(font)
self.ramLabel.setObjectName("ramLabel")
self.ramUnit = QtWidgets.QComboBox(self.tabOption)
self.ramUnit.setGeometry(QtCore.QRect(140, 40, 41, 22))
self.ramUnit.setObjectName("ramUnit")
self.ramUnit.addItem("")
self.ramUnit.addItem("")
self.ramUnit.addItem("")
self.profileLabel = QtWidgets.QLabel(self.tabOption)
self.profileLabel.setGeometry(QtCore.QRect(10, 10, 41, 21))
font = QtGui.QFont()
font.setFamily("UltraLight")
font.setPointSize(10)
self.profileLabel.setFont(font)
self.profileLabel.setObjectName("profileLabel")
self.logo = QtWidgets.QLabel(self.tabOption)
self.logo.setGeometry(QtCore.QRect(180, 10, 231, 151))
self.logo.setStyleSheet("image: url(:/logo/logo.png);")
self.logo.setText("")
self.logo.setObjectName("logo")
self.javaLabel = QtWidgets.QLabel(self.tabOption)
self.javaLabel.setGeometry(QtCore.QRect(10, 70, 61, 21))
font = QtGui.QFont()
font.setFamily("UltraLight")
font.setPointSize(10)
self.javaLabel.setFont(font)
self.javaLabel.setObjectName("javaLabel")
self.javaInput = QtWidgets.QLineEdit(self.tabOption)
self.javaInput.setGeometry(QtCore.QRect(80, 70, 101, 20))
self.javaInput.setObjectName("javaInput")
self.javaLabelOptinal = QtWidgets.QLabel(self.tabOption)
self.javaLabelOptinal.setGeometry(QtCore.QRect(10, 80, 61, 21))
font = QtGui.QFont()
font.setFamily("나눔바른고딕 UltraLight")
font.setPointSize(6)
self.javaLabelOptinal.setFont(font)
self.javaLabelOptinal.setObjectName("javaLabelOptinal")
self.launch = QtWidgets.QCommandLinkButton(self.tabOption)
self.launch.setGeometry(QtCore.QRect(10, 110, 171, 41))
self.launch.setObjectName("launch")
self.tab.addTab(self.tabOption, "")
self.tabConsole = QtWidgets.QWidget()
self.tabConsole.setObjectName("tabConsole")
self.console = QtWidgets.QTextBrowser(self.tabConsole)
self.console.setGeometry(QtCore.QRect(10, 10, 391, 131))
self.console.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.console.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
self.console.setPlaceholderText("")
self.console.setObjectName("console")
self.commandInput = QtWidgets.QLineEdit(self.tabConsole)
self.commandInput.setGeometry(QtCore.QRect(10, 150, 391, 20))
self.commandInput.setText("")
self.commandInput.setObjectName("commandInput")
self.tab.addTab(self.tabConsole, "")
MainWindow.setCentralWidget(self.frame)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setEnabled(True)
self.menubar.setGeometry(QtCore.QRect(0, 0, 441, 21))
font = QtGui.QFont()
font.setFamily("나눔바른고딕 UltraLight")
font.setPointSize(10)
self.menubar.setFont(font)
self.menubar.setToolTip("Settings about profiles")
self.menubar.setObjectName("menubar")
self.menuProfiles = QtWidgets.QMenu(self.menubar)
self.menuProfiles.setObjectName("menuProfiles")
self.menuSettings = QtWidgets.QMenu(self.menubar)
self.menuSettings.setObjectName("menuSettings")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
font = QtGui.QFont()
font.setFamily("")
font.setPointSize(10)
self.statusbar.setFont(font)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionCreate_new_profile = QtWidgets.QAction(MainWindow)
font = QtGui.QFont()
font.setFamily("나눔바른고딕 UltraLight")
font.setPointSize(10)
self.actionCreate_new_profile.setFont(font)
self.actionCreate_new_profile.setObjectName("actionCreate_new_profile")
self.actionDelete_a_profile = QtWidgets.QAction(MainWindow)
font = QtGui.QFont()
font.setFamily("나눔바른고딕 UltraLight")
font.setPointSize(10)
self.actionDelete_a_profile.setFont(font)
self.actionDelete_a_profile.setObjectName("actionDelete_a_profile")
self.actionProfile_Settings = QtWidgets.QAction(MainWindow)
font = QtGui.QFont()
font.setFamily("UltraLight")
font.setPointSize(10)
self.actionProfile_Settings.setFont(font)
self.actionProfile_Settings.setObjectName("actionProfile_Settings")
self.actionGlobal_settings = QtWidgets.QAction(MainWindow)
font = QtGui.QFont()
font.setFamily("UltraLight")
font.setPointSize(10)
self.actionGlobal_settings.setFont(font)
self.actionGlobal_settings.setObjectName("actionGlobal_settings")
self.actionAuto_completes = QtWidgets.QAction(MainWindow)
font = QtGui.QFont()
font.setFamily("UltraLight")
font.setPointSize(10)
self.actionAuto_completes.setFont(font)
self.actionAuto_completes.setObjectName("actionAuto_completes")
self.menuProfiles.addAction(self.actionCreate_new_profile)
self.menuProfiles.addAction(self.actionDelete_a_profile)
self.menuSettings.addAction(self.actionProfile_Settings)
self.menuSettings.addAction(self.actionGlobal_settings)
self.menuSettings.addSeparator()
self.menuSettings.addAction(self.actionAuto_completes)
self.menubar.addAction(self.menuProfiles.menuAction())
self.menubar.addAction(self.menuSettings.menuAction())
self.retranslateUi(MainWindow)
self.tab.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.ramLabel.setText(_translate("MainWindow", "RAM:"))
self.ramUnit.setItemText(0, _translate("MainWindow", "GB"))
self.ramUnit.setItemText(1, _translate("MainWindow", "MB"))
self.ramUnit.setItemText(2, _translate("MainWindow", "KB"))
self.profileLabel.setText(_translate("MainWindow", "Profile:"))
self.javaLabel.setText(_translate("MainWindow", "Java Path:"))
self.javaLabelOptinal.setText(_translate("MainWindow", "(Optinal)"))
self.launch.setText(_translate("MainWindow", "Launch Bukkit!"))
self.tab.setTabText(self.tab.indexOf(self.tabOption), _translate("MainWindow", "Launch Options"))
self.tab.setTabText(self.tab.indexOf(self.tabConsole), _translate("MainWindow", "Console"))
self.menuProfiles.setTitle(_translate("MainWindow", "Profiles"))
self.menuSettings.setTitle(_translate("MainWindow", "Settings"))
self.actionCreate_new_profile.setText(_translate("MainWindow", "Create a new profile.."))
self.actionCreate_new_profile.setShortcut(_translate("MainWindow", "Alt+C"))
self.actionDelete_a_profile.setText(_translate("MainWindow", "Delete a profile.."))
self.actionDelete_a_profile.setShortcut(_translate("MainWindow", "Alt+D"))
self.actionProfile_Settings.setText(_translate("MainWindow", "Profile settings.."))
self.actionProfile_Settings.setShortcut(_translate("MainWindow", "Alt+S"))
self.actionGlobal_settings.setText(_translate("MainWindow", "Global settings.."))
self.actionGlobal_settings.setShortcut(_translate("MainWindow", "Alt+Shift+S"))
self.actionAuto_completes.setText(_translate("MainWindow", "Auto completes.."))
self.actionAuto_completes.setShortcut(_translate("MainWindow", "Alt+A"))
import resource_rc
但它会导致如下错误。
ImportError:没有名为“resource_rc”的模块
我已经尝试在 StackOverflow 中找到此错误,但没有人收到此错误。
我正在使用 Python 3.5 和 PyQt 5.6。(我知道 PyQt 与 Python 3.5 不兼容,但除此之外我没有任何错误)
现在,在我删除最后一行代码后,代码可以正常工作:'import resource_rc'
但这条线到底在做什么?