我使用PYQT5来制作一个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()
的函数来设置小部件,但从未调用这些函数相关问题 更多 >
编程相关推荐