import sys
from PyQt5.
QtGui import
QIcon
def __init__(self):
super().__init__()
self.title = 'Test'
self.left = 10
self.top = 10
self.width = 640
self.height = 480
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.
tabWidget.
addTab(QWidget(),
"Page 1") self.
tabWidget.
addTab(QWidget(),
"Page 2") self.button1.clicked.connect(lambda: self.tabWidget.setCurrentIndex(0))
self.button2.clicked.connect(self.button2_clicked)
self.layout.addWidget(self.tabWidget)
self.layout.addWidget(self.button1)
self.layout.addWidget(self.button2)
self.setLayout(self.layout)
self.show()
def button2_clicked(self):
self.tabWidget.setCurrentIndex(1)
if __name__ == '__main__':
ex = App()
sys.exit(app.exec_())
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QTabWidget, QPushButton
from PyQt5.QtGui import QIcon
class App(QWidget):
def __init__(self):
super().__init__()
self.title = 'Test'
self.left = 10
self.top = 10
self.width = 640
self.height = 480
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.layout = QVBoxLayout(self)
self.tabWidget = QTabWidget(self)
self.tabWidget.addTab(QWidget(), "Page 1")
self.tabWidget.addTab(QWidget(), "Page 2")
self.button1 = QPushButton("Button 1", self)
self.button1.clicked.connect(lambda: self.tabWidget.setCurrentIndex(0))
self.button2 = QPushButton("Button 2", self)
self.button2.clicked.connect(self.button2_clicked)
self.layout.addWidget(self.tabWidget)
self.layout.addWidget(self.button1)
self.layout.addWidget(self.button2)
self.setLayout(self.layout)
self.show()
def button2_clicked(self):
self.tabWidget.setCurrentIndex(1)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
Bookmarks