File tree Expand file tree Collapse file tree 1 file changed +115
-0
lines changed
Expand file tree Collapse file tree 1 file changed +115
-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.geometry('200x200')
8+
9+ window.title("Cálculo Área do Retângulo")
10+
11+
12+
13+ def calcular():
14+
15+ try:
16+
17+ comprimento = float(entrada1.get())
18+
19+ largura = float(entrada2.get())
20+
21+
22+
23+ area = comprimento*largura
24+
25+
26+
27+ msg4["text"] = area
28+
29+
30+
31+ except ValueError:
32+
33+ msg4["text"] = "Valores Inválidos"
34+
35+
36+
37+
38+
39+
40+
41+ def limpar():
42+
43+ entrada1.delete(0,END)
44+
45+ entrada2.delete(0,END)
46+
47+
48+
49+ msg4.config(text="0")
50+
51+
52+
53+ msg1 = Label(window, text="Comprimento do Retângulo:")
54+
55+ msg1.pack()
56+
57+
58+
59+ entrada1 = Entry(window)
60+
61+ entrada1.pack()
62+
63+ entrada1.focus()
64+
65+
66+
67+ msg2 = Label(window, text="Largura do Retângulo:")
68+
69+ msg2.pack()
70+
71+
72+
73+ entrada2 = Entry(window)
74+
75+ entrada2.pack()
76+
77+
78+
79+ botoes_frame = Frame(window)
80+
81+ botoes_frame.pack()
82+
83+
84+
85+ calcular_botao = Button(botoes_frame, text="Calcular", command=calcular)
86+
87+ calcular_botao.pack(side = LEFT)
88+
89+
90+
91+ espaco_botoes = Frame(botoes_frame, width=20)
92+
93+ espaco_botoes.pack(side = LEFT)
94+
95+
96+
97+ limpar_botao = Button(botoes_frame, text="Limpar", command=limpar)
98+
99+ limpar_botao.pack(side=LEFT)
100+
101+
102+
103+ msg3 = Label(window, text="Resultado:")
104+
105+ msg3.pack()
106+
107+
108+
109+ msg4 = Label(window, text="0", fg="red")
110+
111+ msg4.pack()
112+
113+
114+
115+ window.mainloop()
You can’t perform that action at this time.
0 commit comments