【发布时间】:2019-07-11 12:28:26
【问题描述】:
我已经使用 tkinter 构建了一个应用程序以在单个平台上执行不同的分析,但现在我正在尝试将其转换为 PyQT 以改进演示文稿的可视化。我的应用由两个不同的框架组成,可以通过主框架的按钮访问。
在 tkinter 中,我创建了一个用于切换帧的 Controller 类,但我对 PyQt 真的很陌生,我无法实现它或任何合理的错误代码。我在下面简化了我的代码。
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class MainWindow(object):
def setupUi(self, MainFrame):
MainFrame.setObjectName("MainFrame")
MainFrame.resize(870, 230)
MainFrame.setFrameShape(QFrame.Box)
self.Function1Button = QPushButton(MainFrame)
#I want to go Function 1's frame with this button
self.Function1Button.clicked.connect(????)
self.Function2Button = QPushButton(MainFrame)
#I want to go Function 2's frame with this button
self.Function2Button.clicked.connect(????)
class Function1(object):
def setupUi(self, Frame):
Frame.setObjectName("Frame")
Frame.resize(870, 230)
self.BackButton = QPushButton(MainFrame)
# I want to go previous frame with this button
self.BackButton.clicked.connect(????)
self.Function2Button = QPushButton(MainFrame)
#I want to go Function 2's frame with this button
self.Function2Button.clicked.connect(????)
self.ExecuteButton = QPushButton(MainFrame)
self.ExecuteButton.clicked.connect(self.runfunc)
def runfunc(self):
# Computations
class Function2(object):
def setupUi(self, Frame):
Frame.setObjectName("Frame")
Frame.resize(870, 230)
self.BackButton = QPushButton(MainFrame)
self.BackButton.clicked.connect(????)
self.Function1Button = QPushButton(MainFrame)
#I want to go Function 1's frame with this button
self.Function1Button.clicked.connect(????)
self.ExecuteButton = QPushButton(MainFrame)
self.ExecuteButton.clicked.connect(self.runfunc)
def runfunc(self):
# Computations
我想在开始时打开主窗口,然后使用主窗口上的按钮打开函数的框架。 使用功能框架内的后退按钮,我想返回前一帧。 而且我还想使用 Function1Button 从功能 1 到达功能 2 的框架,反之亦然。
【问题讨论】:
-
您是否研究过可堆叠小部件?我认为这听起来像是您想要实现的目标。
标签: python python-3.x pyqt pyqt5