【问题标题】:Error with exit code -1073740791 (0xC0000409) in pythonpython中的退出代码-1073740791(0xC0000409)出错
【发布时间】:2019-07-02 23:43:51
【问题描述】:

所以我尝试制作的程序仅接受 2018-2050 之间的有效月份和年份,但 pycharm 会显示“进程以退出代码 -1073740791 (0xC0000409) 完成”消息而崩溃,我知道它在哪一行执行该操作,但我不知道如何修复它,这是我正在使用的代码,当单击 ok 时,错误出现在最后一个 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.x pycharm


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      正如你所提到的,问题在于函数accepted。如果您打算将其用作类方法,则应将其定义为:

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

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

      @staticmethod
      def accepted(month, year):
          ....
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-11-20
        • 2018-11-06
        • 1970-01-01
        • 2018-09-01
        • 2019-02-02
        • 1970-01-01
        • 2022-09-25
        • 1970-01-01
        相关资源
        最近更新 更多