Repository navigation
Expand file tree
/
Copy pathculculator.py
More file actions
65 lines (62 loc) · 1.76 KB
/
Copy pathculculator.py
File metadata and controls
65 lines (62 loc) · 1.76 KB
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
from functools import partial
import tkinter as tk
import re
window = tk.Tk()
labeles= ['C', '1','4','7','','CE','2','5','8','0','+/-','3','6','9','.','/','*','+','-','=']
count = 0
numOfClicks = 0
radio = 0
def inserting(position):
global numOfClicks
global radio
numOfClicks+=1
match labeles[position]:
case "CE":
numOfClicks = 0
inp.delete(0, tk.END)
return
case "C":
numOfClicks-=2
inp.delete(numOfClicks, tk.END)
return
case "+/-":
if radio == 0:
radio = 1
inp.insert(0, "-")
elif radio == 1:
radio = 0
inp.delete(0, 1)
return
case "=":
culcution()
return
inp.insert(numOfClicks, labeles[position])
def culcution():
raw = inp.get()
verification = 0
pattern = r'[\+\-\*\/]+'
saparation = re.split(pattern,raw)
for i in range(len(saparation)):
if saparation[i].isdigit() == True:
verification = 0
else:
verification = 1
if verification == 0:
inp.delete(0, tk.END)
inp.insert(0,eval(raw))
else:
inp.delete(0, tk.END)
inp.insert(0,"enter number")
table = tk.Frame()
inp = tk.Entry(master=window, width=30)
inp.pack()
for i in range(4):
for j in range(5):
frame = tk.Frame(master=table, borderwidth=1)
frame.grid (column=i, row=j, padx=3, pady=3)
position = labeles[count]
label = tk.Button(master=frame, text=(position) ,pady=10 ,padx=10, command=partial(inserting, count))
count += 1
label.pack()
table.pack()
window.mainloop()