I've been trying to make an application using Pyside6 and can't seem to understand why we can't create a QDialog having QTabWidget with just functions. I am not sure if I am making a mistake somewhere so, here is the code I've wrote:
Imports:
from PySide6.QtWidgets import (QMessageBox, QApplication, QWidget, QGridLayout, QLabel, QMainWindow, QTabWidget,QVBoxLayout)
from sys import argv
2 Tabs function:
def WelPage():grid = QGridLayout()wel_tab = QWidget()wel_tab.setLayout(grid)lab_name = QLabel("This is a label")git_link = QLabel("This is a link")git_link.setOpenExternalLinks(True)yt_link = QLabel("Another Link")yt_link.setOpenExternalLinks(True)grid.addWidget(lab_name, 0, 1)grid.addWidget(git_link, 1, 0)grid.addWidget(yt_link, 1, 3)def AboutPage():about_tab = QWidget()lo = QVBoxLayout()purpose = QLabel("A really long label")lo.addWidget(purpose)about_tab.setLayout(lo)
And the main function:
def main():w = QWidget()layout = QVBoxLayout()tw = QTabWidget()w.resize(450, 250)w.setWindowTitle('Window Title')layout.addWidget(tw)tw.addTab(WelPage(), "Welcome Screen")tw.addTab(AboutPage(), "About")tw.show()w.setLayout(layout)w.show()app.exec()if __name__ == "__main__":app = QApplication(argv)main()
Output:
All this does is render a blank Dialog. Not sure why that is. Why must I be forced to use a class rather than this method?