簡體   English   中英

python pyqt5選項卡內容未顯示

[英]python pyqt5 tab contents not displaying

我正在使用PYQT5制作一個具有2個選項卡的GUI應用程序。 在一個選項卡('tImp')上我想使用文件瀏覽器,在另一個選項卡(tRec)上我想要一個按鈕。 我已經編碼了我想在選項卡上看到的內容,但是執行腳本時,我看到的是選項卡,但沒有看到內容(文件瀏覽器和按鈕)。 以下是我到目前為止的內容:

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_())

任何幫助,將不勝感激。

您定義了名為tImp()tRec()函數來設置小部件,但是您從不調用這些函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM