我正在使用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_())
任何帮助都将不胜感激。
答案 0 :(得分:0)
您定义了名为tImp()
和tRec()
的函数来设置小部件,但您从不调用这些函数。