File tree Expand file tree Collapse file tree 1 file changed +111
-0
lines changed
Expand file tree Collapse file tree 1 file changed +111
-0
lines changed Original file line number Diff line number Diff line change 1+ from tkinter import*
2+
3+
4+
5+ window = Tk()
6+
7+ window.title("Calculadora - área de um triângulo")
8+
9+ window.geometry('200x200')
10+
11+
12+
13+ def calcular():
14+
15+ try:
16+
17+ base = float(entrada1.get())
18+
19+ altura = float(entrada2.get())
20+
21+
22+
23+ area = (base*altura)/2
24+
25+
26+
27+ msg4.config(text=f"{area}")
28+
29+
30+
31+ except ValueError:
32+
33+ msg4.config(text="Valores incorretos")
34+
35+
36+
37+ def limpar():
38+
39+ entrada1.delete(0,END)
40+
41+ entrada2.delete(0,END)
42+
43+
44+
45+ msg4.config(text="0")
46+
47+
48+
49+ msg1 = Label(window, text="Base do Triângulo:")
50+
51+ msg1.pack()
52+
53+
54+
55+ entrada1 = Entry(window)
56+
57+ entrada1.pack()
58+
59+ entrada1.focus()
60+
61+
62+
63+ msg2 = Label(window, text="Altura do Triângulo:")
64+
65+ msg2.pack()
66+
67+
68+
69+ entrada2 = Entry(window)
70+
71+ entrada2.pack()
72+
73+
74+
75+ frame_botoes = Frame(window)
76+
77+ frame_botoes.pack()
78+
79+
80+
81+ calcular_botao = Button(frame_botoes,text="Calcular", command = calcular)
82+
83+ calcular_botao.pack(side=LEFT)
84+
85+
86+
87+ frame_espaco = Frame(frame_botoes, width='75')
88+
89+ frame_espaco.pack()
90+
91+
92+
93+ limpar_botao = Button(frame_botoes, text="Limpar", command=limpar)
94+
95+ limpar_botao.pack(side=RIGHT)
96+
97+
98+
99+ msg3 = Label(window, text="Resultado:")
100+
101+ msg3.pack()
102+
103+
104+
105+ msg4 = Label(window, text="0", fg="red")
106+
107+ msg4.pack()
108+
109+
110+
111+ window.mainloop()
You can’t perform that action at this time.
0 commit comments