首页 > 解决方案 > python中的退出代码-1073740791(0xC0000409)出错

问题描述

所以我试图制作的程序只接受 2018-2050 之间的有效月份和年份,但 pycharm 会显示“进程以退出代码-1073740791(0xC0000409)完成”消息而崩溃,我知道它在哪一行执行此操作,但我不知道如何修复它,这是我正在使用的代码,当单击确定时,错误出现在最后一个 elif 中。正如其他帖子中所建议的那样,我已经尝试重新安装 python 和 pycharm,但没有任何反应。

import sys
from PyQt5.QtWidgets import (QVBoxLayout,QHBoxLayout,QPushButton,
QLineEdit,QApplication,QLabel,QCheckBox,QWidget)

class Window(QWidget):
def __init__(self):
    super().__init__()
    self.init_ui()


def accepted(month, year):
    conf = True
    try:
        int(month)
        int(year)
    except ValueError:
        conf = False
    if conf:
        if (int(month) > 12 or int(month) < 1) or (int(year) < 2019 or 
int(year) > 2050):
            conf = False
    return conf

def init_ui(self):

    self.btn1=QPushButton('OK')
    self.btn2=QPushButton('Clear')
    self.btn3=QPushButton('Cancel')

    self.txt1=QLabel('Month input')
    self.txt2=QLabel('Year Input')

    self.b1=QLineEdit()
    self.b2=QLineEdit()

    h_box1: QHBoxLayout=QHBoxLayout()
    h_box1.addWidget(self.txt1)
    h_box1.addWidget(self.b1)

    h_box2 = QHBoxLayout()
    h_box2.addWidget(self.txt2)
    h_box2.addWidget(self.b2)

    h_box3=QHBoxLayout()
    h_box3.addWidget(self.btn1)
    h_box3.addWidget(self.btn2)
    h_box3.addWidget(self.btn3)


    layout=QVBoxLayout()
    layout.addLayout(h_box1)
    layout.addLayout(h_box2)
    layout.addLayout(h_box3)

    self.setLayout(layout)
    self.setWindowTitle('Calendar Manager')
    self.show()

    self.btn1.clicked.connect(self.buttons)
    self.btn2.clicked.connect(self.buttons)
    self.btn3.clicked.connect(self.buttons)

def buttons(self):
    clicked=self.sender()
    if clicked.text() == 'Clear':
        self.b1.clear()
        self.b2.clear()
    elif clicked.text() == 'Cancel':
        sys.exit()
    elif clicked.text() == 'OK':
        if not accepted(self.b1.text(),self.b2.text()):
            self.b1.clear()
            self.b2.clear()
        else:
            pass

app=QApplication(sys.argv)
a_window=Window()
sys.exit(app.exec_())

标签: python-3.xpycharm

解决方案


所以问题是 self 在两个实例中,第一个是 def 中的参数接受,其次是 self.accepted 当我调用它时。


推荐阅读