Skip to content

Commit 15d7585

Browse files
committed
15/02/23
1 parent 025552e commit 15d7585

File tree

1 file changed

+255
-0
lines changed

1 file changed

+255
-0
lines changed

calculator.py

+255
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
from PyQt5.QtCore import Qt
2+
from PyQt5.QtWidgets import QWidget, QApplication,QPushButton,QLabel,QLineEdit
3+
# global
4+
start_bool = False
5+
light_bool = True
6+
# main
7+
calc = QApplication([]) # app
8+
window = QWidget() #window
9+
window.setGeometry(200,100,350,500) #size
10+
window.setStyleSheet('background-color:black;color:blue') #css
11+
window.setWindowTitle('MyCalc')
12+
line = QLabel(window)
13+
line.setGeometry(25,40,300,70)
14+
line.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px;padding-top:10px;') #css line
15+
line.setAlignment(Qt.AlignRight)
16+
# buttons
17+
18+
# clear
19+
20+
label_clear = QPushButton(window)
21+
label_clear.setText('C')
22+
label_clear.setGeometry(25,130,60,60) #size
23+
label_clear.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px;') #css line
24+
25+
# backspace
26+
27+
label_backspace = QPushButton(window)
28+
label_backspace.setText('<-')
29+
label_backspace.setGeometry(265,130,60,60) #size
30+
label_backspace.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px') #css line
31+
32+
# +
33+
34+
label_plus = QPushButton(window)
35+
label_plus.setText('+')
36+
label_plus.setGeometry(265,200,60,60) #size
37+
label_plus.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
38+
39+
40+
# -
41+
42+
label_minus = QPushButton(window)
43+
label_minus.setText('-')
44+
label_minus.setGeometry(265,270,60,60) #size
45+
label_minus.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
46+
47+
# *
48+
49+
label_k = QPushButton(window)
50+
label_k.setText('*')
51+
label_k.setGeometry(265,340,60,60) #size
52+
label_k.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
53+
54+
# /
55+
56+
label_b = QPushButton(window)
57+
label_b.setText('/')
58+
label_b.setGeometry(265,410,60,60) #size
59+
label_b.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
60+
61+
# =
62+
63+
label_result = QPushButton(window)
64+
label_result.setText('=')
65+
label_result.setGeometry(105,410,140,60) #size
66+
label_result.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
67+
68+
# (
69+
70+
label_oldi = QPushButton(window)
71+
label_oldi.setText('(')
72+
label_oldi.setGeometry(105,130,60,60) #qavs
73+
label_oldi.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
74+
75+
# )
76+
77+
label_orqa = QPushButton(window)
78+
label_orqa.setText(')')
79+
label_orqa.setGeometry(185,130,60,60) #qavs
80+
label_orqa.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
81+
82+
83+
# raqmalar
84+
85+
# 1
86+
87+
label_bir = QPushButton(window)
88+
label_bir.setText('1')
89+
label_bir.setGeometry(25,200,60,60) #size
90+
label_bir.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
91+
92+
# 2
93+
94+
label_ikki = QPushButton(window)
95+
label_ikki.setText('2')
96+
label_ikki.setGeometry(105,200,60,60) #size
97+
label_ikki.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
98+
99+
# 3
100+
101+
label_uch = QPushButton(window)
102+
label_uch.setText('3')
103+
label_uch.setGeometry(185,200,60,60) #size
104+
label_uch.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
105+
106+
# 4
107+
108+
label_tort = QPushButton(window)
109+
label_tort.setText('4')
110+
label_tort.setGeometry(25,270,60,60) #size
111+
label_tort.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
112+
113+
# 5
114+
115+
label_besh = QPushButton(window)
116+
label_besh.setText('5')
117+
label_besh.setGeometry(105,270,60,60) #size
118+
label_besh.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
119+
120+
# 6
121+
122+
label_olti = QPushButton(window)
123+
label_olti.setText('6')
124+
label_olti.setGeometry(185,270,60,60) #size
125+
label_olti.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
126+
127+
# 7
128+
129+
label_yetti = QPushButton(window)
130+
label_yetti.setText('7')
131+
label_yetti.setGeometry(25,340,60,60) #size
132+
label_yetti.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
133+
134+
# 8
135+
136+
label_sakkiz = QPushButton(window)
137+
label_sakkiz.setText('8')
138+
label_sakkiz.setGeometry(105,340,60,60) #size
139+
label_sakkiz.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
140+
141+
# 9
142+
143+
label_toqqiz = QPushButton(window)
144+
label_toqqiz.setText('9')
145+
label_toqqiz.setGeometry(185,340,60,60) #size
146+
label_toqqiz.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
147+
148+
# 0
149+
150+
label_nol = QPushButton(window)
151+
label_nol.setText('0')
152+
label_nol.setGeometry(25,410,60,60) #size
153+
label_nol.setStyleSheet('background-color:white;color:black;font-size:35px;border-radius:15px')
154+
155+
# methots
156+
157+
def yoz():
158+
line.setText('salom')
159+
...
160+
def uchir():
161+
line.setText('')
162+
def back():
163+
line.setText(line.text()[:-1:])
164+
def plus():
165+
line.setText(f"{line.text()}+")
166+
def minus():
167+
line.setText(f"{line.text()}-")
168+
def kop():
169+
line.setText(f"{line.text()}*")
170+
def bol():
171+
line.setText(f"{line.text()}/")
172+
def old():
173+
line.setText(f"{line.text()}(")
174+
def orqa():
175+
line.setText(f"{line.text()})")
176+
177+
# raqam
178+
179+
def raqam_1():
180+
line.setText(f"{line.text()}1")
181+
def raqam_2():
182+
line.setText(f"{line.text()}2")
183+
def raqam_3():
184+
line.setText(f"{line.text()}3")
185+
def raqam_4():
186+
line.setText(f"{line.text()}4")
187+
def raqam_5():
188+
line.setText(f"{line.text()}5")
189+
def raqam_6():
190+
line.setText(f"{line.text()}6")
191+
def raqam_7():
192+
line.setText(f"{line.text()}7")
193+
def raqam_8():
194+
line.setText(f"{line.text()}8")
195+
def raqam_9():
196+
line.setText(f"{line.text()}9")
197+
def raqam_0():
198+
line.setText(f"{line.text()}0")
199+
# clear
200+
201+
label_clear.clicked.connect(uchir)
202+
203+
# backspace
204+
205+
label_backspace.clicked.connect(back)
206+
207+
# +
208+
209+
label_plus.clicked.connect(plus)
210+
211+
# -
212+
213+
label_minus.clicked.connect(minus)
214+
215+
# *
216+
217+
label_k.clicked.connect(kop)
218+
219+
# /
220+
221+
label_b.clicked.connect(bol)
222+
223+
# (
224+
225+
label_oldi.clicked.connect(old)
226+
227+
# )
228+
229+
label_orqa.clicked.connect(orqa)
230+
231+
# raqamlar
232+
label_bir.clicked.connect(raqam_1)
233+
234+
label_ikki.clicked.connect(raqam_2)
235+
label_uch.clicked.connect(raqam_3)
236+
label_tort.clicked.connect(raqam_4)
237+
label_besh.clicked.connect(raqam_5)
238+
label_olti.clicked.connect(raqam_6)
239+
label_yetti.clicked.connect(raqam_7)
240+
label_sakkiz.clicked.connect(raqam_8)
241+
label_toqqiz.clicked.connect(raqam_9)
242+
label_nol.clicked.connect(raqam_0)
243+
244+
245+
# equal
246+
def eq():
247+
try:
248+
line.setText(str(eval(line.text())))
249+
except:
250+
line.setText('Error')
251+
label_result.clicked.connect(eq)
252+
253+
window.show()
254+
calc.exec_()
255+
# not pause

0 commit comments

Comments
 (0)