我知道它可能看起来像重复但不是。我尝试了一切,我无法打开第二个窗口。我有1个主类打开主播放器窗口(成功)。 这是我的主要课程:
class Main(QtGui.QMainWindow, Ui_Main_Window):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.ui = Ui_Main_Window()
self.ui.setupUi(self)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = Main()
window.show()
check_db()
sys.exit(app.exec_())
然后我有所谓的A类和B类。类A
在程序启动时打开,因为它从main启动。类B
是一个必须从此方法运行的小窗口:
def create_new_window(self):
self.LibSettings = LibSettings()
self.LibSettings.show()
LibSettings
上课:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'library_settings.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class LibSettings(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(537, 325)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.gridLayout_2 = QtGui.QGridLayout(self.centralwidget)
self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
self.listView = QtGui.QListView(self.centralwidget)
self.listView.setFrameShape(QtGui.QFrame.NoFrame)
self.listView.setFrameShadow(QtGui.QFrame.Plain)
self.listView.setObjectName(_fromUtf8("listView"))
self.gridLayout_2.addWidget(self.listView, 2, 0, 1, 1)
self.lineEdit = QtGui.QLineEdit(self.centralwidget)
self.lineEdit.setCursor(QtGui.QCursor(QtCore.Qt.IBeamCursor))
self.lineEdit.setAutoFillBackground(True)
self.lineEdit.setClearButtonEnabled(True)
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.gridLayout_2.addWidget(self.lineEdit, 0, 0, 1, 1)
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.pushButton_4 = QtGui.QPushButton(self.centralwidget)
self.pushButton_4.setFocusPolicy(QtCore.Qt.NoFocus)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8("PycharmProjects/SirenPlayer v0.1/artwork/plus.png")),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_4.setIcon(icon)
self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
self.verticalLayout.addWidget(self.pushButton_4)
self.pushButton_3 = QtGui.QPushButton(self.centralwidget)
self.pushButton_3.setFocusPolicy(QtCore.Qt.NoFocus)
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(_fromUtf8("PycharmProjects/SirenPlayer v0.1/artwork/minus.png")),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_3.setIcon(icon1)
self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
self.verticalLayout.addWidget(self.pushButton_3)
self.verticalLayout_2 = QtGui.QVBoxLayout()
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem)
self.pushButton_5 = QtGui.QPushButton(self.centralwidget)
self.pushButton_5.setFocusPolicy(QtCore.Qt.NoFocus)
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(_fromUtf8("PycharmProjects/SirenPlayer v0.1/artwork/cancel.png")),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_5.setIcon(icon2)
self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
self.verticalLayout_2.addWidget(self.pushButton_5)
spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem1)
self.pushButton_6 = QtGui.QPushButton(self.centralwidget)
self.pushButton_6.setFocusPolicy(QtCore.Qt.NoFocus)
icon3 = QtGui.QIcon()
icon3.addPixmap(QtGui.QPixmap(_fromUtf8("PycharmProjects/SirenPlayer v0.1/artwork/ok.png")), QtGui.QIcon.Normal,
QtGui.QIcon.Off)
self.pushButton_6.setIcon(icon3)
self.pushButton_6.setObjectName(_fromUtf8("pushButton_6"))
self.verticalLayout_2.addWidget(self.pushButton_6)
self.verticalLayout.addLayout(self.verticalLayout_2)
self.gridLayout_2.addLayout(self.verticalLayout, 0, 1, 3, 1)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_2.sizePolicy().hasHeightForWidth())
self.pushButton_2.setSizePolicy(sizePolicy)
self.pushButton_2.setMinimumSize(QtCore.QSize(35, 35))
self.pushButton_2.setMaximumSize(QtCore.QSize(35, 35))
self.pushButton_2.setFocusPolicy(QtCore.Qt.NoFocus)
self.pushButton_2.setText(_fromUtf8(""))
self.pushButton_2.setIcon(icon)
self.pushButton_2.setIconSize(QtCore.QSize(35, 35))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.horizontalLayout.addWidget(self.pushButton_2)
self.pushButton = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
self.pushButton.setMinimumSize(QtCore.QSize(35, 35))
self.pushButton.setMaximumSize(QtCore.QSize(35, 35))
self.pushButton.setFocusPolicy(QtCore.Qt.NoFocus)
self.pushButton.setText(_fromUtf8(""))
self.pushButton.setIcon(icon1)
self.pushButton.setIconSize(QtCore.QSize(35, 35))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.horizontalLayout.addWidget(self.pushButton)
spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem2)
self.gridLayout_2.addLayout(self.horizontalLayout, 1, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 537, 19))
self.menubar.setObjectName(_fromUtf8("menubar"))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.pushButton_4.setText(_translate("MainWindow", "Browse", None))
self.pushButton_3.setText(_translate("MainWindow", "Clear selected", None))
self.pushButton_5.setText(_translate("MainWindow", "Cancel", None))
self.pushButton_6.setText(_translate("MainWindow", "Apply", None))
课程A
和B
都没有任何__init__
方法。它们由QtCreator
生成,并且只有Class
和def setupUI
小部件设置和定位。课程A
(UI_Main_Window
)如何在没有问题的情况下启动而另一个(LibSettings
)没有问题。我对此很新,这是一个里程碑,所以我无法继续前进。欢迎任何帮助。请为脑死亡者解释。