因此,基本上在某人的帮助下,我能够想出代码来创建一个有两个框架的GUI。一个在左边,一个在右边。但是我在为实际应用程序编写相同的代码时遇到了困难。你知道吗
也就是说,这里的代码非常基本,因为它只包含一个主函数。我该如何重写这段代码,就像我在这里尝试的那样。你知道吗
import sys
from PyQt4 import QtGui, QtCore
class Window(QtGui.QMainWindow):
def __init__(self):
super(Window,self).__init__()
self.setGeometry(50,50,500,300)
self.setWindowTitle("PyQt4 Tuts")
self.home()
def home(self):
mainWindow = QtGui.QWidget()
mainLayout = QtGui.QGridLayout(mainWindow)
frameLeft = QtGui.QFrame(mainWindow)
frameLeft.setFrameShape(QtGui.QFrame.StyledPanel)
frameLeft.setFrameShadow(QtGui.QFrame.Raised)
gridLayoutLeft = QtGui.QGridLayout(frameLeft)
mainLayout.addWidget(frameLeft, 0, 0, 1, 1, QtCore.Qt.AlignVCenter)
frameRigth = QtGui.QFrame(mainWindow)
frameRigth.setFrameShape(QtGui.QFrame.StyledPanel)
frameRigth.setFrameShadow(QtGui.QFrame.Raised)
gridLayoutRigth = QtGui.QGridLayout(frameRigth)
mainLayout.addWidget(frameRigth, 0, 1, 1, 1, QtCore.Qt.AlignVCenter)
tabs = QtGui.QTabWidget()
gridLayoutRigth.addWidget(tabs, 0, 0, 1, 1, QtCore.Qt.AlignVCenter)
button = QtGui.QPushButton('test')
gridLayoutLeft.addWidget(button, 0, 0, 1, 1, QtCore.Qt.AlignVCenter)
# Create tabs
tab1 = QtGui.QWidget()
tab2 = QtGui.QWidget()
# Set layout of first tab
vBoxlayout = QtGui.QVBoxLayout()
pushButton1 = QtGui.QPushButton("Start")
pushButton2 = QtGui.QPushButton("Settings")
pushButton3 = QtGui.QPushButton("Stop")
vBoxlayout.addWidget(pushButton1)
vBoxlayout.addWidget(pushButton2)
vBoxlayout.addWidget(pushButton3)
tab1.setLayout(vBoxlayout)
# Add tabs
tabs.addTab(tab1, "Tab 1")
tabs.addTab(tab2, "Tab 2")
mainWindow.show()
self.show()
def close_application(self):
print("Whooaa so custom!")
sys.exit()
def run():
app=QtGui.QApplication(sys.argv)
GUI=Window()
sys.exit(app.exec_())
run()
我的主要问题是我在这里自我表现()但也主窗口.show()我不知道该用哪一个,也不知道如何消除一个,所以我只需要一个。你知道吗
要让球滚起来:
你想“展示”你刚刚实现的类
QMainWindow
。 此外,这个类需要内容,您可以在mainwindow
中正确地收集这些内容,因此请使用setCentralWidget()
:最后
close_application()
永远不会被调用,您可以将它连接到一个按钮:或覆盖closingEvent:
相关问题 更多 >
编程相关推荐