Skip to content

Commit c5af070

Browse files
authored
refactor (#33)
1 parent 85dcbb1 commit c5af070

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

FluentCalculator.py

+35-34
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,34 @@
44
import sv_ttk
55
import ntkutils
66

7-
def btnClick(numbers, event=None):
7+
def btnClick(numbers):
88
global operator
9-
tex_input2.set('')
9+
content2.set('')
1010
operator=operator+str(numbers)
11-
tex_input.set(operator)
11+
content.set(operator)
1212

1313
def btnClearDisplay():
1414
global operator
15-
tex_input2.set("")
16-
tex_input.set("0")
15+
content2.set("")
16+
content.set("0")
1717
operator=""
1818

19-
def btnEqualsInput(event=None):
19+
def btnEqualsInput():
2020
try:
2121
global operator
2222
sumup=str(eval(operator))
23-
tex_input2.set(operator)
24-
tex_input.set(sumup)
23+
content2.set(operator)
24+
content.set(sumup)
2525
operator=""
2626
except:
27-
tex_input.set("Error")
27+
content.set("Error")
2828
operator=""
2929

30-
def backspace(event=None):
30+
def backspace():
3131
global operator
3232
operator = operator[:-1]
33-
tex_input2.set("")
34-
tex_input.set(operator)
33+
content2.set("")
34+
content.set(operator)
3535

3636
def aot():
3737
if always_on_top.get() == 1:
@@ -42,14 +42,15 @@ def aot():
4242
def square():
4343
try:
4444
global operator
45-
tex_input2.set(operator + '²')
45+
content2.set(operator + '²')
4646
ans = float(operator)
4747
squr = ans*ans
48-
tex_input.set(str(squr))
4948
operator =""
49+
if str(squr).endswith(".0"): squr = str(squr).rstrip(".0")
50+
content.set(str(squr))
5051
except:
51-
tex_input2.set("")
52-
tex_input.set("Error")
52+
content2.set("")
53+
content.set("Error")
5354
operator=""
5455

5556
root=tk.Tk()
@@ -68,37 +69,37 @@ def square():
6869
ntkutils.blur_window_background(root)
6970

7071
operator=""
71-
tex_input= StringVar()
72-
tex_input2 = StringVar()
73-
tex_input.set("0")
74-
txtDisplay = Label(root, textvariable=tex_input, font=('Segoe UI Variable Display Semibold','35'),anchor="e",width=11).place(x=0, y=60)
75-
txtDisplay2 =Label(root,textvariable=tex_input2, font=('Segoe UI Variable Display Semibold','15'),anchor="e",width=11, fg='#707476').place(x=162,y=30)
76-
7772
always_on_top = BooleanVar()
78-
alwaysontop=ttk.Checkbutton(root, text="", variable = always_on_top,onvalue=1, offvalue=0, style="Toggle.TButton",command=lambda:aot()).place(x=4, y=148, height=53, width=76)
79-
btnsquare=ttk.Button(root, text="x²", command=lambda:square()).place(x=4, y=203, height=53, width=76)
80-
btn7=ttk.Button(root, text="7", command=lambda:btnClick(7)).place(x=4, y=258, height=53, width=76)
81-
btn4=ttk.Button(root, text="4", command=lambda:btnClick(4)).place(x=4, y=313, height=53, width=76)
82-
btn1=ttk.Button(root, text="1", command=lambda:btnClick(1)).place(x=4, y=368, height=53, width=76)
73+
content= StringVar()
74+
content2 = StringVar()
75+
content.set("0")
8376

84-
openbtn=ttk.Button(root, text="(", command=lambda:btnClick('(')).place(x=82, y=148, height=53, width=76)
85-
btnClear=ttk.Button(root, text="C", command=btnClearDisplay).place(x=82, y= 203, height=53, width=76)
86-
btn8=ttk.Button(root, text="8", command=lambda:btnClick(8)).place(x=82, y=258, height=53, width=76)
87-
btn5=ttk.Button(root, text="5", command=lambda:btnClick(5)).place(x=82, y=313, height=53, width=76)
77+
Display = Label(root, textvariable=content, font=('Segoe UI Variable Display Semibold','35'),anchor="e",width=11).place(x=0, y=60)
78+
Display2 =Label(root,textvariable=content2, font=('Segoe UI Variable Display Semibold','15'),anchor="e",width=11, fg='#707476').place(x=162,y=30)
79+
80+
btn1=ttk.Button(root, text="1", command=lambda:btnClick(1)).place(x=4, y=368, height=53, width=76)
8881
btn2=ttk.Button(root, text="2", command=lambda:btnClick(2)).place(x=82, y=368, height=53, width=76)
82+
btn3=ttk.Button(root, text="3", command=lambda:btnClick(3)).place(x=160, y=368, height=53, width=76)
83+
btn4=ttk.Button(root, text="4", command=lambda:btnClick(4)).place(x=4, y=313, height=53, width=76)
84+
btn5=ttk.Button(root, text="5", command=lambda:btnClick(5)).place(x=82, y=313, height=53, width=76)
85+
btn6=ttk.Button(root, text="6", command=lambda:btnClick(6)).place(x=160, y=313, height=53, width=76)
86+
btn7=ttk.Button(root, text="7", command=lambda:btnClick(7)).place(x=4, y=258, height=53, width=76)
87+
btn8=ttk.Button(root, text="8", command=lambda:btnClick(8)).place(x=82, y=258, height=53, width=76)
88+
btn9=ttk.Button(root, text="9", command=lambda:btnClick(9)).place(x=160, y=258, height=53, width=76)
8989
btn0=ttk.Button(root, text="0", command=lambda:btnClick(0)).place(x=4, y=423, height=53, width=154)
9090

91+
alwaysontop=ttk.Checkbutton(root, text="", variable = always_on_top,onvalue=1, offvalue=0, style="Toggle.TButton",command=lambda:aot()).place(x=4, y=148, height=53, width=76)
92+
openbtn=ttk.Button(root, text="(", command=lambda:btnClick('(')).place(x=82, y=148, height=53, width=76)
9193
closebtn=ttk.Button(root, text=")", command=lambda:btnClick(')')).place(x=160, y=148, height=53, width=76)
94+
btnClear=ttk.Button(root, text="C", command=btnClearDisplay).place(x=82, y= 203, height=53, width=76)
9295
Backspace = ttk.Button(root, text='', command=backspace).place(x=160, y=203, height=53, width=76)
93-
btn9=ttk.Button(root, text="9", command=lambda:btnClick(9)).place(x=160, y=258, height=53, width=76)
94-
btn6=ttk.Button(root, text="6", command=lambda:btnClick(6)).place(x=160, y=313, height=53, width=76)
95-
btn3=ttk.Button(root, text="3", command=lambda:btnClick(3)).place(x=160, y=368, height=53, width=76)
9696
btndot=ttk.Button(root, text=".", command=lambda:btnClick('.')).place(x=160, y=423, height=53, width=76)
9797

9898
Divsion=ttk.Button(root, text="", command=lambda:btnClick("/")).place(x=238, y=148, height=53, width=76)
9999
Multiple=ttk.Button(root, text="", command=lambda:btnClick("*")).place(x=238, y=203, height=53, width=76)
100100
Subtraction=ttk.Button(root, text="", command=lambda:btnClick("-")).place(x=238, y=258, height=53, width=76)
101101
Addition=ttk.Button(root, text="", command=lambda:btnClick("+")).place(x=238, y=313, height=53, width=76)
102+
btnsquare=ttk.Button(root, text="x²", command=lambda:square()).place(x=4, y=203, height=53, width=76)
102103
equal=ttk.Button(root, text="", command=btnEqualsInput).place(x=238, y=368, height=108, width=76)
103104

104105
root.bind('<Return>', btnEqualsInput)

0 commit comments

Comments
 (0)