so the program that I am trying to make accepts only a valid month and year between 2018-2050 but pycharm crushes with the message "Process finished with exit code -1073740791 (0xC0000409)" and I know in which line it does that, but I dont know how to fix it, here is the code I am using and the error appers in the last elif when ok is clicked. I have tried reinstalling python and pycharm, as suggested in other posts but nothing happens.
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_())
So the problem is the self in two instances, first as an argument in def accepted and secondly the self.accepted when I call it.
As you mentioned, the problem is with function accepted
. If you intended it to be a class method, it should have been defined as:
def accepted(self, month, year):
....
You don't use 'self' in the method, so it could be turned into a static method:
@staticmethod
def accepted(month, year):
....
User contributions licensed under CC BY-SA 3.0