简体   繁体   English

python pyqt5选项卡内容未显示

[英]python pyqt5 tab contents not displaying

I am using PYQT5 to make an GUI application which will have 2 tabs. 我正在使用PYQT5制作一个具有2个选项卡的GUI应用程序。 On one tab ('tImp') I want to use a file browser, on the other tab (tRec) I want to have a push button. 在一个选项卡('tImp')上我想使用文件浏览器,在另一个选项卡(tRec)上我想要一个按钮。 I have coded what I want to see on the tab, but when I execute the script, I see the tabs, but not the contents (file browser and push button). 我已经编码了我想在选项卡上看到的内容,但是执行脚本时,我看到的是选项卡,但没有看到内容(文件浏览器和按钮)。 Below is what I have so far: 以下是我到目前为止的内容:

import sys from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QWidget, QAction, QTabWidget,QVBoxLayout, QInputDialog, QLineEdit, QFileDialog from PyQt5.QtGui import QIcon

class App(QMainWindow):

    def __init__(self):
        super().__init__()
        self.title = 'Budget'
        self.left = 10
        self.top = 40
        self.width = 1200
        self.height = 600
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)

        self.table_widget = MyTableWidget(self)
        self.setCentralWidget(self.table_widget)

        self.show()

class MyTableWidget(QWidget):     

    def __init__(self, parent):   
        super(QWidget, self).__init__(parent)
        self.layout = QVBoxLayout(self)

        # Initialize tab screen
        self.tabs = QTabWidget()
        self.tImp = QWidget()   
        self.tRec = QWidget()
        self.tabs.resize(1200,600) 

        # Create Import tab
        def tImp():
            self.tImp.layout = QVBoxLayout(self)
            self.tImp.layout.addWidget(self.openFileNamesDialog)
            self.tImp.setLayout(self.tImp.layout)

        # Create file browser Widget        
        def openFileNamesDialog(self):    
            options = QFileDialog.Options()
            options |= QFileDialog.DontUseNativeDialog
            files, _ = QFileDialog.getOpenFileNames(self,"QFileDialog.getOpenFileNames()", "","All Files (*);;Format Files (*.csv)", options=options)
            if files:
                print(files)     

        # Create Reconcile tab
        def tRec():
            self.tRec.layout = QVBoxLayout(self)
            self.pushButton1 = QPushButton("Commit")
            self.tRec.layout.addWidget(self.pushButton1)
            self.tRec.setLayout(self.tRec.layout)

        # Add tabs
        self.tabs.addTab(self.tImp,"Import")
        self.tabs.addTab(self.tRec,"Reconcile")

        # Add tabs to widget        
        self.layout.addWidget(self.tabs)
        self.setLayout(self.layout)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())

Any help would be appreciated. 任何帮助,将不胜感激。

您定义了名为tImp()tRec()函数来设置小部件,但是您从不调用这些函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM