Chico_Leme
(usa Ubuntu)
Enviado em 03/04/2017 - 00:31h
[code]Boa noite.
Andei pesquisando e não achei nenhuma calculadora com interface programada em Python, todas era pelo terminal.
Então tentei criar uma kkkkk
Mas sou novo em programação..
A interface da calculadora está pronta, mas não consigo somar,subtrair,mutiplicar ou dividir dois numeros diferentes.
Eu só consegui fazer o seguinte..
Se eu clico, por exemplo, no 2 e clico em + "somar" ele vai somar 2. Se eu clico no 8 e depois no + ele soma mais 8. E assim respectivamente para cada operador matemático.
Alguem pode me ajudar?
Segue o algoritmo:
#!/usr/bin/python
#-*- coding: utf-8 -*-
from Tkinter import *
item=0.0
item1=1.0
item2=2.0
item3=3.0
item4=4.0
item5=5.0
item6=6.0
item7=7.0
item8=8.0
item9=9.0
def numb():
item2 == float(scr.configure("text")[4]) == 1
scr.configure(text=float(item))
print (item)
def numb1():
item1 == float(scr.configure("text")[4]) == 1
scr.configure(text=float(item1))
print (item1)
def numb2():
item2 == float(scr.configure("text")[4])==2
scr.configure(text=float(item2))
print (item2)
def numb3():
item3 == float(scr.configure("text")[4])==3
scr.configure(text=float(item3))
print (item3)
def numb4():
item4 == float(scr.configure("text")[4])==4
scr.configure(text=float(item4))
print (item4)
def numb5():
item5 == float(scr.configure("text")[4])==5
scr.configure(text=float(item5))
print (item5)
def numb6():
item6 == float(scr.configure("text")[4])==6
scr.configure(text=float(item6))
print (item6)
def numb7():
item7 == float(scr.configure("text")[4])==7
scr.configure(text=float(item7))
print (item7)
def numb8():
item8 == float(scr.configure("text")[4])==8
scr.configure(text=float(item8))
print (item8)
def numb9():
item9 == float(scr.configure("text")[4])
scr.configure(text=float(item9))
print (item9)
def summ(): # Arithmetic operation
arith = float(scr.configure("text")[4])
try:
arith = arith + arith
scr.configure(text=float(arith))
except:
pass
print(arith)
def subt(): # Arithmetic operation
arith = float(scr.configure("text")[4])
try:
arith = arith - 1
scr.configure(text=float(arith))
except:
pass
def multp(): # Arithmetic operation
arith = float(scr.configure("text")[4])
try:
arith = arith * arith
scr.configure(text=float(arith))
except:
pass
print(arith)
def divs(): # Arithmetic operation
arith = float(scr.configure("text")[4])
try:
arith = arith / arith
scr.configure(text=float(arith))
except:
pass
print(arith)
scr = Label(text="0") ; scr.pack(fill="both") # Screen calculator
cal3 = Frame() ; cal3.pack() # creat for the botton of calculator
cal2 = Frame() ; cal2.pack()
cal1 = Frame() ; cal1.pack()
cal = Frame() ; cal.pack() # creat for the botton of calculator
n = Button(cal, text=0, command=numb) ; n.pack(side="left")
n1 = Button(cal1, text=1, command=numb1) ; n1.pack(side="left")
n2 = Button(cal1, text=2, command=numb2) ; n2.pack(side="left")
n3 = Button(cal1, text=3, command=numb3) ; n3.pack(side="left")
n4 = Button(cal2, text=4, command=numb4) ; n4.pack(side="left")
n5 = Button(cal2, text=5, command=numb5) ; n5.pack(side="left")
n6 = Button(cal2, text=6, command=numb6) ; n6.pack(side="left")
n7 = Button(cal3, text=7, command=numb7) ; n7.pack(side="left")
n8 = Button(cal3, text=8, command=numb8) ; n8.pack(side="left")
n9 = Button(cal3, text=9, command=numb9) ; n9.pack(side="left")
eqal_ = Button(cal, text="=") ; eqal_.pack(side="right") # Arithmetic operation
sum_ = Button(cal, text="+", command=summ) ; sum_.pack(side="right") # Arithmetic operation
sub_ = Button(cal1, text="-", command=subt) ; sub_.pack(side="right") # Arithmetic operation
mul_ = Button(cal2, text="*", command=multp) ; mul_.pack(side="right") # Arithmetic operation
div_ = Button(cal3, text="/", command=divs) ; div_.pack(side="right") # Arithmetic operation
cal.master.title("Calculadora")
cal.master.geometry("165x150")
cal.mainloop()