Python中退出代码-1073740791(0xC0000409)的错误

时间:2019-02-08 17:18:55

标签: python-3.x pycharm

所以我要制作的程序仅接受2018-2050年之间的有效月份和年份,但是pycharm崩溃并显示消息“进程以退出代码-1073740791(0xC0000409)完成”,我知道它在哪一行,但我不知道如何解决它,这是我正在使用的代码,单击确定后,错误会出现在最后一个省略号中。我已经尝试按照其他帖子中的建议重新安装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_())

2 个答案:

答案 0 :(得分:1)

所以问题出在两个实例中的self,首先是作为def中的参数接受,其次是我调用它时self.accepted。

答案 1 :(得分:0)

正如您所提到的,问题在于函数 accepted。如果你打算将它作为一个类方法,它应该被定义为:

def accepted(self, month, year):
    ....

你没有在方法中使用'self',所以它可以变成一个静态方法:

@staticmethod
def accepted(month, year):
    ....
相关问题