【发布时间】:2019-07-23 09:29:53
【问题描述】:
我创建了一个带有控制器文件的 gui 来在窗口之间切换。这些文件包括几个参数,这些参数将由以前的窗口设置,因此,大小可能非常大。因此,我需要创建一个滚动条才能到达最后一个元素,但想知道如何在我的代码中实现这一点。
来自控制器.py
import sys
from PyQt5 import QtCore, QtWidgets
from firstwindow import Login
class Controller:
def __init__(self):
pass
def show_login(self):
self.login = Login()
self.login.switch_window.connect(self.show_main)
self.login.show()
def show_main(self):
self.MAP = self.login.MAP
#Parameters from file
self.NUM = self.login.spinBoxNUM.value()
self.login.close()
def main():
app = QtWidgets.QApplication(sys.argv)
controller = Controller()
controller.show_login()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
并从登录类文件中: 第一个窗口.py
import sys
from PyQt5 import QtCore, QtWidgets, QtGui
class Login(QtWidgets.QWidget):
switch_window = QtCore.pyqtSignal()
def __init__(self):
QtWidgets.QWidget.__init__(self)
self.setupUi(self)
self.setWindowTitle('First')
def setupUi(self, FirstWindow):
FirstWindow.setObjectName("First")
FirstWindow.setEnabled(True)
FirstWindow.resize(675,776)
FirstWindow.setFocusPolicy(QtCore.Qt.TabFocus)
layout = QtWidgets.QGridLayout()
#Lots of elements + buttons: example:
self.spinBoxNUM = QtWidgets.QSpinBox()
layout.addWidget(self.spinBoxNUM,1,2)
self.spinBoxLEVELS = QtWidgets.QSpinBox()
self.spinBoxLEVELS.setValue(2)
self.spinBoxLEVELS.setMaximum(156)
layout.addWidget(self.spinBoxLEVELS,11,2)
#CONTINUE AND QUIT BUTTON
self.QuitButton = QtWidgets.QPushButton("Quit")
self.QContinueButton = QtWidgets.QPushButton("Continue")
#actions
self.QuitButton.clicked.connect(FirstWindow.close)
self.QContinueButton.clicked.connect(self.login)
layout.addWidget(self.QuitButton,15,1)
layout.addWidget(self.QContinueButton,15,2)
self.setLayout(layout)
def login(self):
self.MAP = [[1 for x in range(4)]for y in range(self.LEVELS)]
self.switch_window.emit()
【问题讨论】:
-
对不起,我对此很陌生,我应该做更多的最小还是可重现的问题?
-
为了向您推荐一些东西,我需要运行您的示例并重现问题。我如何运行您的示例?
-
谢谢,我相信它现在已经修复了:)
标签: python user-interface pyqt5 scrollbar