Skip to content

Commit 67d9937

Browse files
committed
Section-02 Updated
1 parent 45ac881 commit 67d9937

13 files changed

+473
-71
lines changed

Section-02/07. Event Handling.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def __init__(self):
1313

1414
self.create_widget()
1515

16-
1716
def create_widget(self):
1817
hbox = QHBoxLayout()
1918
btn = QPushButton("Change Text")
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Form implementation generated from reading ui file 'event.ui'
2+
#
3+
# Created by: PyQt6 UI code generator 6.4.2
4+
#
5+
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
6+
# run again. Do not edit this file unless you know what you are doing.
7+
8+
9+
from PyQt6 import QtCore, QtGui, QtWidgets
10+
11+
12+
class Ui_Form(object):
13+
def setupUi(self, Form):
14+
Form.setObjectName("Form")
15+
Form.resize(400, 250)
16+
self.verticalLayout = QtWidgets.QVBoxLayout(Form)
17+
self.verticalLayout.setObjectName("verticalLayout")
18+
self.horizontalLayout = QtWidgets.QHBoxLayout()
19+
self.horizontalLayout.setObjectName("horizontalLayout")
20+
self.btn_click = QtWidgets.QPushButton(parent=Form)
21+
font = QtGui.QFont()
22+
font.setFamily("Arial Black")
23+
font.setPointSize(10)
24+
font.setBold(True)
25+
self.btn_click.setFont(font)
26+
self.btn_click.setObjectName("btn_click")
27+
self.btn_click.clicked.connect(self.click_me)
28+
self.horizontalLayout.addWidget(self.btn_click)
29+
self.lineEdit = QtWidgets.QLineEdit(parent=Form)
30+
self.lineEdit.setObjectName("lineEdit")
31+
self.horizontalLayout.addWidget(self.lineEdit)
32+
self.verticalLayout.addLayout(self.horizontalLayout)
33+
self.label = QtWidgets.QLabel(parent=Form)
34+
self.label.setText("")
35+
self.label.setObjectName("label")
36+
self.verticalLayout.addWidget(self.label)
37+
38+
self.retranslateUi(Form)
39+
QtCore.QMetaObject.connectSlotsByName(Form)
40+
41+
def click_me(self):
42+
mytext = self.lineEdit.text()
43+
self.label.setText(mytext)
44+
45+
def retranslateUi(self, Form):
46+
_translate = QtCore.QCoreApplication.translate
47+
Form.setWindowTitle(_translate("Form", "Qt Designer Application"))
48+
self.btn_click.setText(_translate("Form", "Click ME"))
49+
self.lineEdit.setPlaceholderText(_translate("Form", "Please Enter Your Name"))
50+
51+
52+
if __name__ == "__main__":
53+
import sys
54+
app = QtWidgets.QApplication(sys.argv)
55+
Form = QtWidgets.QWidget()
56+
ui = Ui_Form()
57+
ui.setupUi(Form)
58+
Form.show()
59+
sys.exit(app.exec())

Section-02/Calculator.py

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# Form implementation generated from reading ui file 'Calculator.ui'
2+
#
3+
# Created by: PyQt6 UI code generator 6.4.2
4+
#
5+
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
6+
# run again. Do not edit this file unless you know what you are doing.
7+
8+
9+
from PyQt6 import QtCore, QtGui, QtWidgets
10+
11+
12+
class Ui_Form(object):
13+
def setupUi(self, Form):
14+
Form.setObjectName("Form")
15+
Form.resize(450, 211)
16+
self.verticalLayout = QtWidgets.QVBoxLayout(Form)
17+
self.verticalLayout.setObjectName("verticalLayout")
18+
self.horizontalLayout = QtWidgets.QHBoxLayout()
19+
self.horizontalLayout.setObjectName("horizontalLayout")
20+
self.label = QtWidgets.QLabel(parent=Form)
21+
font = QtGui.QFont()
22+
font.setPointSize(10)
23+
font.setBold(True)
24+
self.label.setFont(font)
25+
self.label.setObjectName("label")
26+
self.horizontalLayout.addWidget(self.label)
27+
spacerItem = QtWidgets.QSpacerItem(20, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
28+
self.horizontalLayout.addItem(spacerItem)
29+
self.lineEdit_1st = QtWidgets.QLineEdit(parent=Form)
30+
font = QtGui.QFont()
31+
font.setPointSize(10)
32+
self.lineEdit_1st.setFont(font)
33+
self.lineEdit_1st.setObjectName("lineEdit_1st")
34+
self.horizontalLayout.addWidget(self.lineEdit_1st)
35+
self.verticalLayout.addLayout(self.horizontalLayout)
36+
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
37+
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
38+
self.label_2 = QtWidgets.QLabel(parent=Form)
39+
font = QtGui.QFont()
40+
font.setPointSize(10)
41+
font.setBold(True)
42+
self.label_2.setFont(font)
43+
self.label_2.setObjectName("label_2")
44+
self.horizontalLayout_2.addWidget(self.label_2)
45+
spacerItem1 = QtWidgets.QSpacerItem(28, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
46+
self.horizontalLayout_2.addItem(spacerItem1)
47+
self.lineEdit_2nd = QtWidgets.QLineEdit(parent=Form)
48+
self.lineEdit_2nd.setObjectName("lineEdit_2nd")
49+
self.horizontalLayout_2.addWidget(self.lineEdit_2nd)
50+
self.verticalLayout.addLayout(self.horizontalLayout_2)
51+
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
52+
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
53+
54+
#-----------Addition Section---------------
55+
self.addbtn = QtWidgets.QPushButton(parent=Form)
56+
font = QtGui.QFont()
57+
font.setFamily("Arial")
58+
font.setPointSize(10)
59+
font.setBold(True)
60+
self.addbtn.setFont(font)
61+
self.addbtn.setObjectName("addbtn")
62+
self.addbtn.clicked.connect(self.add)
63+
self.horizontalLayout_3.addWidget(self.addbtn)
64+
65+
#-----------Subtraction Section---------------
66+
self.subtractbtn = QtWidgets.QPushButton(parent=Form)
67+
font = QtGui.QFont()
68+
font.setFamily("Arial")
69+
font.setPointSize(10)
70+
font.setBold(True)
71+
self.subtractbtn.setFont(font)
72+
self.subtractbtn.setObjectName("subtractbtn")
73+
self.subtractbtn.clicked.connect(self.subtraction)
74+
self.horizontalLayout_3.addWidget(self.subtractbtn)
75+
76+
#-----------Multiplication Section---------------
77+
self.intobtn = QtWidgets.QPushButton(parent=Form)
78+
font = QtGui.QFont()
79+
font.setFamily("Arial")
80+
font.setPointSize(10)
81+
font.setBold(True)
82+
self.intobtn.setFont(font)
83+
self.intobtn.setObjectName("intobtn")
84+
self.intobtn.clicked.connect(self.multiplication)
85+
self.horizontalLayout_3.addWidget(self.intobtn)
86+
87+
#-----------dividition Section---------------
88+
self.dividbtn = QtWidgets.QPushButton(parent=Form)
89+
font = QtGui.QFont()
90+
font.setFamily("Arial")
91+
font.setPointSize(10)
92+
font.setBold(True)
93+
self.dividbtn.setFont(font)
94+
self.dividbtn.setObjectName("dividbtn")
95+
self.dividbtn.clicked.connect(self.dividition)
96+
self.horizontalLayout_3.addWidget(self.dividbtn)
97+
98+
99+
self.verticalLayout.addLayout(self.horizontalLayout_3)
100+
self.label_result = QtWidgets.QLabel(parent=Form)
101+
self.label_result.setEnabled(True)
102+
font = QtGui.QFont()
103+
font.setPointSize(14)
104+
font.setBold(True)
105+
self.label_result.setFont(font)
106+
self.label_result.setAutoFillBackground(True)
107+
self.label_result.setStyleSheet("QLabel {\n"
108+
"color: green\n"
109+
"}")
110+
self.label_result.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
111+
self.label_result.setObjectName("label_result")
112+
self.verticalLayout.addWidget(self.label_result)
113+
114+
self.retranslateUi(Form)
115+
QtCore.QMetaObject.connectSlotsByName(Form)
116+
117+
#--------------Addition Function-------------
118+
def add(self):
119+
firstnum = int(self.lineEdit_1st.text())
120+
secondnum = int(self.lineEdit_2nd.text())
121+
122+
result = firstnum + secondnum
123+
self.label_result.setText("Addition : {}".format(result))
124+
125+
#--------------Subtraction Function-------------
126+
def subtraction(self):
127+
firstnum = int(self.lineEdit_1st.text())
128+
secondnum = int(self.lineEdit_2nd.text())
129+
130+
result = firstnum - secondnum
131+
self.label_result.setText("Subtraction : {}".format(result))
132+
133+
#--------------Multiplication Function-------------
134+
def multiplication(self):
135+
firstnum = int(self.lineEdit_1st.text())
136+
secondnum = int(self.lineEdit_2nd.text())
137+
138+
result = firstnum * secondnum
139+
self.label_result.setText("Multiplication : {}".format(result))
140+
141+
#--------------dividition Function-------------
142+
def dividition(self):
143+
firstnum = int(self.lineEdit_1st.text())
144+
secondnum = int(self.lineEdit_2nd.text())
145+
146+
result = firstnum / secondnum
147+
self.label_result.setText("Dividition : {}".format(result))
148+
149+
150+
def retranslateUi(self, Form):
151+
_translate = QtCore.QCoreApplication.translate
152+
Form.setWindowTitle(_translate("Form", "Form"))
153+
self.label.setText(_translate("Form", "First Number:"))
154+
self.lineEdit_1st.setPlaceholderText(_translate("Form", "Enter First Number"))
155+
self.label_2.setText(_translate("Form", "Second Number:"))
156+
self.lineEdit_2nd.setPlaceholderText(_translate("Form", "Enter Second Number"))
157+
self.addbtn.setText(_translate("Form", "+"))
158+
self.subtractbtn.setText(_translate("Form", "-"))
159+
self.intobtn.setText(_translate("Form", "*"))
160+
self.dividbtn.setText(_translate("Form", "/"))
161+
self.label_result.setText(_translate("Form", "0"))
162+
163+
164+
if __name__ == "__main__":
165+
import sys
166+
app = QtWidgets.QApplication(sys.argv)
167+
Form = QtWidgets.QWidget()
168+
ui = Ui_Form()
169+
ui.setupUi(Form)
170+
Form.show()
171+
sys.exit(app.exec())

0 commit comments

Comments
 (0)