4
4
import sv_ttk
5
5
import ntkutils
6
6
7
- def btnClick (numbers , event = None ):
7
+ def btnClick (numbers ):
8
8
global operator
9
- tex_input2 .set ('' )
9
+ content2 .set ('' )
10
10
operator = operator + str (numbers )
11
- tex_input .set (operator )
11
+ content .set (operator )
12
12
13
13
def btnClearDisplay ():
14
14
global operator
15
- tex_input2 .set ("" )
16
- tex_input .set ("0" )
15
+ content2 .set ("" )
16
+ content .set ("0" )
17
17
operator = ""
18
18
19
- def btnEqualsInput (event = None ):
19
+ def btnEqualsInput ():
20
20
try :
21
21
global operator
22
22
sumup = str (eval (operator ))
23
- tex_input2 .set (operator )
24
- tex_input .set (sumup )
23
+ content2 .set (operator )
24
+ content .set (sumup )
25
25
operator = ""
26
26
except :
27
- tex_input .set ("Error" )
27
+ content .set ("Error" )
28
28
operator = ""
29
29
30
- def backspace (event = None ):
30
+ def backspace ():
31
31
global operator
32
32
operator = operator [:- 1 ]
33
- tex_input2 .set ("" )
34
- tex_input .set (operator )
33
+ content2 .set ("" )
34
+ content .set (operator )
35
35
36
36
def aot ():
37
37
if always_on_top .get () == 1 :
@@ -42,14 +42,15 @@ def aot():
42
42
def square ():
43
43
try :
44
44
global operator
45
- tex_input2 .set (operator + '²' )
45
+ content2 .set (operator + '²' )
46
46
ans = float (operator )
47
47
squr = ans * ans
48
- tex_input .set (str (squr ))
49
48
operator = ""
49
+ if str (squr ).endswith (".0" ): squr = str (squr ).rstrip (".0" )
50
+ content .set (str (squr ))
50
51
except :
51
- tex_input2 .set ("" )
52
- tex_input .set ("Error" )
52
+ content2 .set ("" )
53
+ content .set ("Error" )
53
54
operator = ""
54
55
55
56
root = tk .Tk ()
@@ -68,37 +69,37 @@ def square():
68
69
ntkutils .blur_window_background (root )
69
70
70
71
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
-
77
72
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" )
83
76
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 )
88
81
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 )
89
89
btn0 = ttk .Button (root , text = "0" , command = lambda :btnClick (0 )).place (x = 4 , y = 423 , height = 53 , width = 154 )
90
90
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 )
91
93
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 )
92
95
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 )
96
96
btndot = ttk .Button (root , text = "." , command = lambda :btnClick ('.' )).place (x = 160 , y = 423 , height = 53 , width = 76 )
97
97
98
98
Divsion = ttk .Button (root , text = "" , command = lambda :btnClick ("/" )).place (x = 238 , y = 148 , height = 53 , width = 76 )
99
99
Multiple = ttk .Button (root , text = "" , command = lambda :btnClick ("*" )).place (x = 238 , y = 203 , height = 53 , width = 76 )
100
100
Subtraction = ttk .Button (root , text = "" , command = lambda :btnClick ("-" )).place (x = 238 , y = 258 , height = 53 , width = 76 )
101
101
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 )
102
103
equal = ttk .Button (root , text = "" , command = btnEqualsInput ).place (x = 238 , y = 368 , height = 108 , width = 76 )
103
104
104
105
root .bind ('<Return>' , btnEqualsInput )
0 commit comments