-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtkinter-calc.py
More file actions
47 lines (38 loc) · 745 Bytes
/
Copy pathtkinter-calc.py
File metadata and controls
47 lines (38 loc) · 745 Bytes
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
import tkinter as tk
text = ''
root = tk.Tk()
root.title('Calc')
font = ('Arial', 16)
lab = tk.Label(
root,
font = font
)
lab.pack()
buttons_group = tk.Frame(root)
buttons_group.pack()
def create_button(num, index: int):
global root
def add_char():
global text
text = text + str(num)
lab.config(text = str(text)) # FIXME
tk.Button(
buttons_group,
text = str(num),
command = add_char,
padx = 1,
pady = 1,
width = 4,
height = 2,
font = font,
).grid(
row = index // 3,
column = index % 3,
sticky = "ew",
padx = 1,
pady = 1,
)
symbols = [1, 2, 3, 4, 5, 6, 7, 8, 9, '=', 0, '<']
for num, signal in enumerate(symbols):
create_button(signal, num)
root.mainloop()