user-interface - 使用 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()
解决方案
推荐阅读
- r - 警告消息:要替换的项目数不是替换长度的倍数
- python - 提高 numpy 中 levenshtein 距离的性能
- elasticsearch - 如何在多个搜索结果中标准化分数
- html - SVG 不适合屏幕 html 的全宽和高度 - 没有响应
- registry - Edge-Chromium GP - 如何将 google 设置为默认值、绕过首次运行对话框以及没有新闻的标签页?
- android - Flutter with Firebase Google 登录:断言失败 network_image_io.dart
- pandas - Pandas:如何使用单独的 y 轴进行绘图,但仍控制顺序?
- pandas - 名称 _stringify_path 未定义
- amazon-web-services - SQS 策略不授予访问权限
- python - 运算符作为 IF 的参数返回 SyntaxError: invalid syntax