# import sys
#
# from PyQt5.QtWidgets import *
#
# from PyQt5 import *
#
# from PyQt5.QtGui import *
#
# from PyQt5.QtCore import *
#
# import random
#
# m=6
#
# s=0
#
# r=0
#
# def guessodd(la2,la1):
#
# global m
#
# global s
#
# global r
#
# #print("number:",end=" ")
#
# r=random.randint(1,12)
#
# #print(r)
#
# if r%2==1:
#
# #print("you guessed correctly. +1 marble")
#
# m=m+1
#
# s=s+1
#
# else:
#
# #print("you guessed incorrectly. -1 marble")
#
# m=m-1
#
# # print(la2.text())
#
# la2.setText('Your marbles:'+str(m))
#
# la1.setText('Number:'+str(r))
#
# la1.repaint()
#
# la2.repaint()
#
# if m<1:
#
# la2.setText("You're out of marbles! please close the window.")
#
# la1.setText('Score:' + str(s))
#
# la2.repaint()
#
# la1.repaint()
#
# def guesseven(la2,la1):
#
# global m
#
# global r
#
# global s
#
# #print("number:", end=" ")
#
# r = random.randint(1, 12)
#
# #print(r)
#
# if r % 2 == 0:
#
# #print("you guessed correctly. +1 marble")
#
# m = m + 1
#
# s=s+1
#
# else:
#
# #print("you guessed incorrectly. -1 marble")
#
# m = m - 1
#
# la2.setText('Your marbles:'+str(m))
#
# la2.repaint()
#
# la1.setText('Number:' + str(r))
#
# la1.repaint()
#
# if m<1:
#
# la2.setText("You're out of marbles! please close the window.")
#
# la1.setText('Score:' + str(s))
#
# la2.repaint()
#
# la1.repaint()
#
# class MyApp(QWidget):
#
# global m
#
# def __init__(self):
#
# super().__init__()
#
# def initUI(self):
#
# label1 = QLabel('Press odd or even button to start.', self)
#
# label2 = QLabel('Your marbles:'+str(m), self)
#
# btno=QPushButton('&odd',self)
#
# btno.clicked.connect(lambda:guessodd(label2,label1))
#
# btne = QPushButton('&even', self)
#
# btne.clicked.connect(lambda: guesseven(label2,label1))
#
#
# btno.setStyleSheet("color: green;"
#
# "background-color: #DC143C")
#
# btne.setStyleSheet("color: orange;"
#
# "background-color: #4169E1")
#
# label2.setStyleSheet("color: green;"
#
# "border-style: solid;"
#
# "border-width: 2px;"
#
# "border-color: #037A76;"
#
# "border-radius: 1px")
#
# label1.setStyleSheet("color: purple;"
#
# "border-style: solid;"
#
# "border-width: 2px;"
#
# "border-color: #ED1B76;"
#
# "border-radius: 1px")
#
#
# vbox = QVBoxLayout()
#
# vbox.addWidget(btno)
#
# vbox.addWidget(btne)
#
# vbox.addWidget(label1)
#
# vbox.addWidget(label2)
#
#
# self.setLayout(vbox)
#
# self.setGeometry(300, 300, 300, 200)
#
# self.setWindowTitle('odd or even')
#
# self.show()
#
# if __name__ == '__main__':
#
# app = QApplication(sys.argv)
#
# ex = MyApp()
#
# ex.initUI()
#
# sys.exit(app.exec_())
import sys
from PyQt5.QtWidgets import *
from PyQt5 import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
m=0
m=int(m)
l=0
l=int(l)
o=0
b=0
b=int(b)
def input(n,la1):
global m
m=m*10
m=m+n
la1.setText(str(m))
la1.repaint()
def operator(c,la1):
global o,m,l,b
if b==1:
operate(la1)
if c=='+':
o='+'
if c=='-':
o='-'
if c=='*':
o='*'
if c=='/':
o='/'
l=m
m=0
b=1
la1.setText(str(m))
la1.repaint()
def clear(la1):
global l,m
l=0
m=0
la1.setText(str(m))
la1.repaint()
def operate(la1):
global l,m,o,b
a=0
a=int(a)
if o=='+':
a=l+m
if o=='-':
a=l-m
if o=='*':
a=l*m
if o=='/':
a=l/m
l=0
m=a
b=0
la1.setText(str(a))
la1.repaint()
class MyApp(QWidget):
global m
def __init__(self):
super().__init__()
def initUI(self):
lbl1 = QLabel('0', self)
btn1 = QPushButton('&1', self)
btn1.clicked.connect(lambda: input(1,lbl1))
btn2 = QPushButton('&2', self)
btn2.clicked.connect(lambda: input(2, lbl1))
btn3 = QPushButton('&3', self)
btn3.clicked.connect(lambda: input(3, lbl1))
btnp=QPushButton('&+',self)
btnp.clicked.connect(lambda: operator("+",lbl1))
btn4 = QPushButton('&4', self)
btn4.clicked.connect(lambda: input(4, lbl1))
btn5 = QPushButton('&5', self)
btn5.clicked.connect(lambda: input(5, lbl1))
btn6 = QPushButton('&6', self)
btn6.clicked.connect(lambda: input(6, lbl1))
btnm = QPushButton('&-', self)
btnm.clicked.connect(lambda: operator("-", lbl1))
btn7 = QPushButton('&7', self)
btn7.clicked.connect(lambda: input(7, lbl1))
btn8 = QPushButton('&8', self)
btn8.clicked.connect(lambda: input(8, lbl1))
btn9 = QPushButton('&9', self)
btn9.clicked.connect(lambda: input(9, lbl1))
btnt = QPushButton('&x', self)
btnt.clicked.connect(lambda: operator("*", lbl1))
btnc = QPushButton('&C', self)
btnc.clicked.connect(lambda: clear(lbl1))
btn0 = QPushButton('&0', self)
btn0.clicked.connect(lambda: input(0, lbl1))
btnd = QPushButton('&÷', self)
btnd.clicked.connect(lambda: operator("/", lbl1))
btne = QPushButton('&=', self)
btne.clicked.connect(lambda: operate(lbl1))
hbox = QHBoxLayout()
hbox.addStretch(1)
hbox.addWidget(lbl1)
hbox.addStretch(0)
hboxr1=QHBoxLayout()
hboxr1.addStretch(1)
hboxr1.addWidget(btn1)
hboxr1.addWidget(btn2)
hboxr1.addWidget(btn3)
hboxr1.addWidget(btnp)
hboxr1.addStretch(1)
hboxr2 = QHBoxLayout()
hboxr2.addStretch(1)
hboxr2.addWidget(btn4)
hboxr2.addWidget(btn5)
hboxr2.addWidget(btn6)
hboxr2.addWidget(btnm)
hboxr2.addStretch(1)
hboxr3 = QHBoxLayout()
hboxr3.addStretch(1)
hboxr3.addWidget(btn7)
hboxr3.addWidget(btn8)
hboxr3.addWidget(btn9)
hboxr3.addWidget(btnt)
hboxr3.addStretch(1)
hboxr4 = QHBoxLayout()
hboxr4.addStretch(1)
hboxr4.addWidget(btnc)
hboxr4.addWidget(btn0)
hboxr4.addWidget(btnd)
hboxr4.addWidget(btne)
hboxr4.addStretch(1)
vbox = QVBoxLayout()
vbox.addWidget(lbl1)
vbox.addStretch(1)
vbox.addLayout(hboxr1)
vbox.addLayout(hboxr2)
vbox.addLayout(hboxr3)
vbox.addLayout(hboxr4)
vbox.addStretch(2)
lbl1.setStyleSheet("color: green;"
"border-style: solid;"
"border-width: 1px;"
"border-color: #0000CD;"
"border-radius: 10px")
btnp.setStyleSheet("color: black;"
"background-color: #FF8C00")
btnm.setStyleSheet("color: black;"
"background-color: #FF8C00")
btnt.setStyleSheet("color: black;"
"background-color: #FF8C00")
btnd.setStyleSheet("color: black;"
"background-color: #FF8C00")
btnc.setStyleSheet("color: black;"
"background-color: #FFD700")
btne.setStyleSheet("color: white;"
"background-color: #4169E1")
self.setLayout(vbox)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('calculator')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
ex.initUI()
sys.exit(app.exec_())