【发布时间】:2017-12-05 18:08:35
【问题描述】:
我学习 pyqt5 并尝试通过单击另一个窗口中的按钮来打开一个新窗口。如果没有 input() 函数,它将立即关闭打开的窗口,所以我输入 input() 以保持窗口打开。窗口将打开很长时间,但随后停止工作。有人能帮我吗 ?谢谢
import sys
from PyQt5.QtWidgets import QApplication, QPushButton,QMainWindow,QWidget
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
class App1(QWidget):
def __init__(self):
super().__init__()
self.title = 'open window'
self.left = 60
self.top = 60
self.width = 320
self.height = 200
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.show()
m.getch()
input() '''here is the problem'''
class App(QMainWindow):
def __init__(self):
super().__init__()
self.title = 'PyQt5 button - pythonspot.com'
self.left = 200
self.top = 200
self.width = 320
self.height = 200
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
button = QPushButton('PyQt5 button', self)
button.setToolTip('This is an example button')
button.move(100, 70)
button.clicked.connect(self.on_click)
self.show()
@pyqtSlot()
def on_click(self):
app1 = QApplication(sys.argv)
ex1 = App1()
sys.exit(app1.exec_())
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
【问题讨论】:
标签: python input error-handling window pyqt5