# def f(s, n,r):
# s = s*n
# n = n-1
# r = r-1
# if r!=0:
# return f(s, n,r)
# else:
# return s
# def f1(r, o):
# o=o*r
# r = r-1
# if r==0:
# return o
# else:
# return f1(r, o)
# n, r = map(int, input().split())
# s=1
# o=1
#
#
#
# print(f(s, n, r)//f1(r, o))
## Ex 3-1. 창 띄우기.
## Ex 5-1. QPushButton.
'''
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
class MyApp(QWidget):
def init(self):
super().__init__()
self.initUI()
def initUI(self):
btn1 = QPushButton('&Button1', self)
btn1.setCheckable(True)
btn1.toggle()
btn2 = QPushButton(self)
btn2.setText('Button&2')
btn3 = QPushButton('Button3', self)
btn3.setEnabled(False)
vbox = QVBoxLayout()
vbox.addWidget(btn1)
vbox.addWidget(btn2)
vbox.addWidget(btn3)
self.setLayout(vbox)
self.setWindowTitle('QPushButton')
self.setGeometry(300, 300, 300, 200)
if name == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())
'''
import sys
from PyQt5.QtWidgets import (QApplication, QWidget, QGridLayout, QLabel, QLineEdit, QTextEdit)
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
class MyApp(QWidget):
def init(self):
super().__init__()
self.fun = 0
self.numberA = 0
self.numberB = 0
self.numberC = 0
self.op = True
###
self.initUI()
def initUI(self):
grid = QGridLayout()
self.setLayout(grid)
self.num1 = QPushButton('1', self)
self.num2 = QPushButton('2', self)
self.num3 = QPushButton('3', self)
self.num4 = QPushButton('4', self)
self.num5 = QPushButton('5', self)
self.num6 = QPushButton('6', self)
self.num7 = QPushButton('7', self)
self.num8 = QPushButton('8', self)
self.num9 = QPushButton('9', self)
self.num0 = QPushButton('0', self)
self.num10 = QPushButton('=', self)
self.num11 = QPushButton('+', self)
self.num12 = QPushButton('-', self)
self.num13 = QPushButton('*', self)
self.num14 = QPushButton('/', self)
self.num1.clicked.connect(self.funcNum1)
self.num2.clicked.connect(self.funcNum2)
self.num3.clicked.connect(self.funcNum3)
self.num4.clicked.connect(self.funcNum4)
self.num5.clicked.connect(self.funcNum5)
self.num6.clicked.connect(self.funcNum6)
self.num7.clicked.connect(self.funcNum7)
self.num8.clicked.connect(self.funcNum8)
self.num9.clicked.connect(self.funcNum9)
self.num0.clicked.connect(self.funcNum0)
self.num10.clicked.connect(self.funcNum10)
self.num11.clicked.connect(self.funcNum11)
self.num12.clicked.connect(self.funcNum12)
self.num13.clicked.connect(self.funcNum13)
self.num14.clicked.connect(self.funcNum14)
grid.addWidget(self.num1, 0, 0)
grid.addWidget(self.num2, 0, 1)
grid.addWidget(self.num3, 0, 2)
grid.addWidget(self.num11, 0, 3)
grid.addWidget(self.num4, 1, 0)
grid.addWidget(self.num5, 1, 1)
grid.addWidget(self.num6, 1, 2)
grid.addWidget(self.num12, 1, 3)
grid.addWidget(self.num7, 2, 0)
grid.addWidget(self.num8, 2, 1)
grid.addWidget(self.num9, 2, 2)
grid.addWidget(self.num13, 2, 3)
grid.addWidget(self.num0, 3, 1)
grid.addWidget(self.num10, 3, 2)
grid.addWidget(self.num14, 3, 3)
self.setWindowTitle('Calculator')
self.setGeometry(300, 300, 300, 200)
def funcNum1(self):
if self.op == True:#앞
self.numberA *= 10
self.numberA += 1
print(self.numberA)
else:# 연산자 뒤
self.numberB *= 10
self.numberB += 1
print(self.numberB)
def funcNum2(self):
if self.op == True: # 앞
self.numberA *= 10
self.numberA += 2
print(self.numberA)
else: # 연산자 뒤
self.numberB *= 10
self.numberB += 2
print(self.numberB)
def funcNum3(self):
if self.op == True: # 앞
self.numberA *= 10
self.numberA += 3
print(self.numberA)
else: # 연산자 뒤
self.numberB *= 10
self.numberB += 3
print(self.numberB)
def funcNum4(self):
if self.op == True: # 앞
self.numberA *= 10
self.numberA += 4
print(self.numberA)
else: # 연산자 뒤
self.numberB *= 10
self.numberB += 4
print(self.numberB)
def funcNum5(self):
if self.op == True: # 앞
self.numberA *= 10
self.numberA += 5
print(self.numberA)
else: # 연산자 뒤
self.numberB *= 10
self.numberB += 5
print(self.numberB)
def funcNum6(self):
if self.op == True: # 앞
self.numberA *= 10
self.numberA += 6
print(self.numberA)
else: # 연산자 뒤
self.numberB *= 10
self.numberB += 6
print(self.numberB)
def funcNum7(self):
if self.op == True: # 앞
self.numberA *= 10
self.numberA += 7
print(self.numberA)
else: # 연산자 뒤
self.numberB *= 10
self.numberB += 7
print(self.numberB)
def funcNum8(self):
if self.op == True: # 앞
self.numberA *= 10
self.numberA += 8
print(self.numberA)
else: # 연산자 뒤
self.numberB *= 10
self.numberB += 8
print(self.numberB)
def funcNum9(self):
if self.op == True: # 앞
self.numberA *= 10
self.numberA += 9
print(self.numberA)
else: # 연산자 뒤
self.numberB *= 10
self.numberB += 9
print(self.numberB)
def funcNum0(self):
if self.op == True: # 앞
self.numberA *= 10
self.numberA += 0
print(self.numberA)
else: # 연산자 뒤
self.numberB *= 10
self.numberB += 0
print(self.numberB)
def funcNum10(self):
if self.fun == '-':
print(self.numberA - self.numberB)
elif self.fun == '*':
print(self.numberA * self.numberB)
elif self.fun == '/':
print(self.numberA / self.numberB)
else:
print(self.numberA + self.numberB)
def funcNum11(self):
self.op = False
def funcNum12(self):
self.op = False
self.fun = '-'
def funcNum13(self):
self.op = False
self.fun = '*'
def funcNum14(self):
self.op = False
self.fun ='/'
if name == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())