-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
102 lines (77 loc) · 4.58 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from tkinter import *
from tkinter import ttk
# color picker
cor1 = "#000000" # preta
cor2= "#FFFFFF" # branca
cor3 = "#2682E4" # azul
cor4 = "#AFB7C0" # cinza
cor5 = "#F67809" # laranja
janela = Tk()
janela.title("Calculadora")
janela.geometry("250x312")
janela.config(bg=cor1)
# criando frames
frame_tela = Frame(janela, width=300, height=56, bg = cor2)
frame_tela.grid(row=0, column=0)
frame_corpo = Frame(janela, width=300, height=340)
frame_corpo.grid(row=1, column=0)
# variavel global
todos_valores = ''
# criando função
def entrar_valores(event):
global todos_valores
todos_valores = todos_valores + str(event)
# passando o valor para a tela
valor_texto.set(todos_valores)
# função para calcular
def calcular():
global todos_valores
resultado = eval(todos_valores)
valor_texto.set(str(resultado))
# criando labels
valor_texto = StringVar()
app_label = Label(frame_tela, textvariable= valor_texto, width = 17, height =2, padx=7, relief=FLAT, anchor="e", justify=RIGHT, font=('Ivy 18'),bg = cor3, fg = cor2)
app_label.place(x=0,y=0)
# limpar a tela
def limpar_tela():
global todos_valores
todos_valores = ""
valor_texto.set("")
# criando botoes
b_1 = Button(frame_corpo, command=limpar_tela, text="C", width = 11, height=2, bg=cor4,fg = cor2, font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_1.place(x=0,y=0)
b_2 = Button(frame_corpo, command=lambda: entrar_valores('%'), text="%", width = 5, height=2, bg=cor4,fg = cor2, font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_2.place(x=118,y=0)
b_3 = Button(frame_corpo, command=lambda: entrar_valores('/'), text="/", width = 7, height=2, bg=cor5, fg = cor2,font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_3.place(x=177,y=0)
b_4 = Button(frame_corpo, command=lambda: entrar_valores('7'), text="7", width = 5, height=2, bg=cor4, fg = cor2,font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_4.place(x=0,y=52)
b_5 = Button(frame_corpo,command=lambda: entrar_valores('8'), text="8", width = 5, height=2, bg=cor4, fg = cor2,font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_5.place(x=59,y=52)
b_6 = Button(frame_corpo, command=lambda: entrar_valores('9'), text="9", width = 5, height=2, bg=cor4, fg = cor2,font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_6.place(x=118,y=52)
b_7 = Button(frame_corpo, command=lambda: entrar_valores('*'), text="*", width = 7, height=2, bg=cor5, fg = cor2,font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_7.place(x=177,y=52)
b_8 = Button(frame_corpo, command=lambda: entrar_valores('4'), text="4", width = 5, height=2, bg=cor4, fg = cor2,font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_8.place(x=0,y=104)
b_9 = Button(frame_corpo, command=lambda: entrar_valores('5'), text="5", width = 5, height=2, bg=cor4, fg = cor2,font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_9.place(x=59,y=104)
b_10 = Button(frame_corpo, command=lambda: entrar_valores('6'), text="6", width = 5, height=2, bg=cor4, fg = cor2,font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_10.place(x=118,y=104)
b_11 = Button(frame_corpo, command=lambda: entrar_valores('-'), text="-", width = 7, height=2, bg=cor5, fg = cor2,font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_11.place(x=177,y=104)
b_12 = Button(frame_corpo, command=lambda: entrar_valores('1'), text="1", width = 5, height=2, bg=cor4, fg = cor2,font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_12.place(x=0,y=156)
b_13 = Button(frame_corpo, command=lambda: entrar_valores('2'), text="2", width = 5, height=2, bg=cor4, fg = cor2,font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_13.place(x=59,y=156)
b_14 = Button(frame_corpo, command=lambda: entrar_valores('3'), text="3", width = 5, height=2, bg=cor4, fg = cor2,font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_14.place(x=118,y=156)
b_15 = Button(frame_corpo, command=lambda: entrar_valores('+'), text="+", width = 7, height=2, bg=cor5, fg = cor2,font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_15.place(x=177,y=156)
b_16 = Button(frame_corpo, command=lambda: entrar_valores('0'), text="0", width = 11, height=2, bg=cor4, fg = cor2,font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_16.place(x=0,y=208)
b_17 = Button(frame_corpo, command=lambda: entrar_valores('.'), text=".", width = 5, height=2, bg=cor4, fg = cor2,font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_17.place(x=118,y=208)
b_18 = Button(frame_corpo, command= calcular, text="=", width = 7, height=2, bg=cor5, fg = cor2,font= ('Ivy 13 bold'), relief= RAISED, overrelief=RIDGE)
b_18.place(x=177,y=208)
janela.mainloop()