44from kivy .uix .gridlayout import GridLayout
55from kivy .uix .label import Label
66
7+
78class myApp (App ):
89 def build (self ):
9- root_widget = BoxLayout (orientation = 'vertical' )
10- output_label = Label (size_hint_y = 0.75 , font_size = 50 )
11- button_symbols = ('1' , '2' , '3' , '+' ,
12- '4' , '5' , '6' , '-' ,
13- '7' , '8' , '9' , '.' ,
14- '0' , '*' , '/' , '=' )
10+ root_widget = BoxLayout (orientation = "vertical" )
11+ output_label = Label (size_hint_y = 0.75 , font_size = 50 )
12+ button_symbols = (
13+ "1" ,
14+ "2" ,
15+ "3" ,
16+ "+" ,
17+ "4" ,
18+ "5" ,
19+ "6" ,
20+ "-" ,
21+ "7" ,
22+ "8" ,
23+ "9" ,
24+ "." ,
25+ "0" ,
26+ "*" ,
27+ "/" ,
28+ "=" ,
29+ )
1530 button_grid = GridLayout (cols = 4 , size_hint_y = 2 )
1631 for symbol in button_symbols :
1732 button_grid .add_widget (Button (text = symbol ))
1833
19- clear_button = Button (text = 'Clear' , size_hint_y = None , height = 100 )
34+ clear_button = Button (text = "Clear" , size_hint_y = None , height = 100 )
35+
2036 def print_button_text (instance ):
2137 output_label .text += instance .text
38+
2239 for button in button_grid .children [1 :]:
2340 button .bind (on_press = print_button_text )
41+
2442 def resize_label_text (label , new_height ):
25- label .fontsize = 0.5 * label .height
43+ label .fontsize = 0.5 * label .height
44+
2645 output_label .bind (height = resize_label_text )
2746
2847 def evaluate_result (instance ):
2948 try :
3049 output_label .text = str (eval (output_label .text ))
3150 except SyntaxError :
32- output_label .text = 'Python Syntax error!'
51+ output_label .text = "Python Syntax error!"
52+
3353 button_grid .children [0 ].bind (on_press = evaluate_result )
3454
3555 def clear_label (instance ):
3656 output_label .text = " "
57+
3758 clear_button .bind (on_press = clear_label )
3859
3960 root_widget .add_widget (output_label )
4061 root_widget .add_widget (button_grid )
4162 root_widget .add_widget (clear_button )
4263 return root_widget
43- myApp ().run ()
64+
65+
66+ myApp ().run ()
0 commit comments