首页 > 解决方案 > 使用 2 .show() 的 PyQt5 无法驾驭任何一个

问题描述

PyQt5 应用程序,我正在构建这个应用程序并且必须使用 2 .show(),当我运行代码时会显示 2 个 GUI。一个空白的 GUI 和我的信息。当我删除第一个 .show() 时,仅显示空白 GUI,而当我删除第二个时,则没有显示任何想法。

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QGridLayout, `enter code here`QLineEdit, QLabel
from PyQt5.QtWidgets import QPushButton, QVBoxLayout, QFormLayout, QPushButton, `enter code here`QTableWidget, QTableWidgetItem
from PyQt5.QtCore import Qt
import sqlite3

class ExerciseTracker(QWidget):
    def __init__(self):
        super().__init__()
        self.myWindow = QWidget()
        self.title = 'Exercise Tracker'
        self.setWindowTitle(self.title)
        self.setGeometry(200, 400, 300, 200)
        self.move(60, 15)
        self.layout = QFormLayout()
        self.layout.addRow(QLabel('<h2>Welcome to the App!</h2>',              parent=self.myWindow))
        line_edit1 = QLineEdit()
        self.layout.addRow('Day of the week: ', line_edit1)
        line_edit2 = QLineEdit()
        self.layout.addRow('Body Part: ', line_edit2)
        line_edit3 = QLineEdit()
        self.layout.addRow('Input Exercise: ', line_edit3)
        line_edit4 = QLineEdit()
        self.layout.addRow('Input Sets: ', line_edit4)
        line_edit5 = QLineEdit()
        self.layout.addRow('Input Reps: ', line_edit5)
        btn1 = QPushButton('Submit')
        self.layout.addRow(btn1)
        btn2 = QPushButton('Show Records')
        self.layout.addRow(btn2)

        self.myWindow.setLayout(self.layout)
        self.myWindow.show()

def main():
    exercise = QApplication(sys.argv)
    view = ExerciseTracker()
    view.show()
    sys.exit(exercise.exec_())

if __name__ =='__main__':
    main()

标签: user-interfacepyqt5qwidget

解决方案


推荐阅读