~ EDIT (원본 질문은 여전히 아래) ~ 새 창에서 self.setGeometry() 호출을 제거하면 정상적으로 작동합니다. 왜 그런가요? 나는 여전히 UI를 구축하고 있지만, 일단 내가이 문제를 계속해서 가지지 않기를 바란다 ...PyQt5에서 새 창을 열 때 내 앱이 닫히는 이유는 무엇입니까?
~ EDIT 2 ~ 그냥 self.resize()가 아님을 깨달았다. setGeometry() ...
self.solved()
:(
난 그냥 PyQt5 학습 그냥 장난 좀하고 있어요. 어떤 이유로 내가 주 응용 프로그램 창에서 새 창을 열 때, 진행 상황을 추적하기 위해 일부 인쇄 문을 넣으면 실제로 새 창을 만들지 못하는 것으로 나타납니다.
주 창 코드 : 여기
import sys
from PyQt5.QtWidgets import QMainWindow, QAction, QApplication
from newLeague import *
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
newLeagueAction = QAction('Create New League', self)
newLeagueAction.setShortcut('Ctrl+N')
newLeagueAction.setStatusTip('Create a new league from scratch')
newLeagueAction.triggered.connect(self.createNewLeague)
openLeagueAction = QAction('Open Existing League', self)
openLeagueAction.setShortcut('Ctrl+E')
openLeagueAction.setStatusTip('Continue with a previously started league')
openLeagueAction.triggered.connect(self.openExistingLeague)
exitAction = QAction('Quit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Quit the application...')
exitAction.triggered.connect(self.close)
self.statusBar()
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('&File')
fileMenu.addAction(newLeagueAction)
fileMenu.addAction(openLeagueAction)
fileMenu.addAction(exitAction)
self.resize(1920, 1080)
self.setWindowTitle("Brackets")
def createNewLeague(self):
'''shows dialog to create a new league'''
self.newLeague = CreateLeague()
self.newLeague.show()
print('New League being created...')
def openExistingLeague(self):
print('Existing League opening...')
def main():
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
두 번째 창입니다 :
from PyQt5.QtWidgets import QMainWindow
class CreateLeague(QMainWindow):
def __init__(self):
super(CreateLeague, self).__init__()
self.initUI()
def initUI(self):
self.setGeometry(600, 500)
self.setWindowTitle('Create A New League')
나는 그런 this 및 this 다른 예를 살펴 보았다, 그리고 나는 내가 무엇인지 확인할 수 없습니다 다른 일을하고 있어요. 저는 생성자에서 parent를 인수로 사용하여 실험했으며 결과도 마찬가지입니다.