I'm making a calender using pyqt5, and it gives me this error when
I Wrote these lines of code: from pyqt5 import QtCore, QtGui, QtWidgets, uic
, and delclass = uic.loaduiType
.
Traceback (most recent call last):
File "C:\Users\hungy\Desktop\Mason Works\Python\Projects\Calender.py", line 7, in <module>
delclass = uic.loadUiType('Del_btn.ui')
File "C:\Users\hungy\AppData\Local\Programs\Python\Python39\lib\site-packages\PyQt5\uic\__init__.py", line 204, in loadUiType
exec(code_string.getvalue(), ui_globals)
File "<string>", line 5
def setupUi(self, del):
^
SyntaxError: invalid syntax
What's wrong with my code?
I tried Changing the name to Delclass
, but that didn't work.
This is my code:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets, uic
# defines the formclasses
calclass = uic.loadUiType("Calender.ui")[0]
addclass = uic.loadUiType('Add_btn.ui')
delclass = uic.loadUiType('Del_btn.ui')
editclass = uic.loadUiType('Edit_btn.ui')
# classes
class Add(QtWidgets.QMainWindow, addclass):
def __init__(self, parent=None):
QtWidgets.QMainWindow.__init__(self, parent)
self.setupUi(self)
# self.Namevalue = Name_Text.value
class Calender(QtWidgets.QMainWindow, calclass):
def __init__(self, parent=None):
QtWidgets.QMainWindow.__init__(self, parent)
self.setupUi(self)
self.Add.triggered.connect(self.add_clicked)
self.Delete.triggered.connect(self.del_clicked)
self.Close_Exit.triggered.connect(self.x_clicked)
def x_clicked(self):
self.close()
def del_clicked(self):
pass
def add_clicked(self):
pass
app = QtWidgets.QApplication(sys.argv)
Window = Calender()
Window.show()
app.exec_()
.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>del</class>
<widget class="QDialog" name="del">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>355</width>
<height>106</height>
</rect>
</property>
<property name="windowTitle">
<string>Del</string>
</property>
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
<widget class="QDialogButtonBox" name="OKCANCEL">
<property name="geometry">
<rect>
<x>-80</x>
<y>60</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QPushButton" name="Why">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>93</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>Why:</string>
</property>
</widget>
<widget class="QPlainTextEdit" name="plainTextEdit">
<property name="geometry">
<rect>
<x>120</x>
<y>10</y>
<width>191</width>
<height>31</height>
</rect>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>OKCANCEL</sender>
<signal>accepted()</signal>
<receiver>del</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>OKCANCEL</sender>
<signal>rejected()</signal>
<receiver>del</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>