4646font = bitmap_font .load_font ("/fonts/Arial-12.bdf" )
4747buttons = []
4848
49- # Some button placement functions
49+ # Some button functions
5050def button_grid (row , col ):
5151 return Coords (BUTTON_MARGIN * (row + 1 ) + BUTTON_WIDTH * row + 20 ,
5252 BUTTON_MARGIN * (col + 1 ) + BUTTON_HEIGHT * col + 40 )
5353
54- def make_button (row , col , label , width = 1 , color = WHITE , text_color = BLACK ):
54+ def add_button (row , col , label , width = 1 , color = WHITE , text_color = BLACK ):
5555 pos = button_grid (row , col )
5656 new_button = Button (x = pos .x , y = pos .y ,
5757 width = BUTTON_WIDTH * width + BUTTON_MARGIN * (width - 1 ),
@@ -60,37 +60,37 @@ def make_button(row, col, label, width=1, color=WHITE, text_color=BLACK):
6060 buttons .append (new_button )
6161 return new_button
6262
63- border = Rect (20 , 8 , 280 , 35 , fill = WHITE , outline = BLACK , stroke = 2 )
64- calc_display = Label (font , text = "0" , color = BLACK , max_glyphs = MAX_DIGITS )
65- calc_display .y = 25
66-
67- clear_button = make_button (0 , 0 , "AC" )
68- make_button (1 , 0 , "+/-" )
69- make_button (2 , 0 , "%" )
70- make_button (3 , 0 , "/" , 1 , ORANGE , WHITE )
71- make_button (0 , 1 , "7" )
72- make_button (1 , 1 , "8" )
73- make_button (2 , 1 , "9" )
74- make_button (3 , 1 , "x" , 1 , ORANGE , WHITE )
75- make_button (0 , 2 , "4" )
76- make_button (1 , 2 , "5" )
77- make_button (2 , 2 , "6" )
78- make_button (3 , 2 , "-" , 1 , ORANGE , WHITE )
79- make_button (0 , 3 , "1" )
80- make_button (1 , 3 , "2" )
81- make_button (2 , 3 , "3" )
82- make_button (3 , 3 , "+" , 1 , ORANGE , WHITE )
83- make_button (0 , 4 , "0" , 2 )
84- make_button (2 , 4 , "." )
85- make_button (3 , 4 , "=" , 1 , ORANGE , WHITE )
86-
8763def find_button (label ):
8864 result = None
8965 for _ , btn in enumerate (buttons ):
9066 if btn .label == label :
9167 result = btn
9268 return result
9369
70+ border = Rect (20 , 8 , 280 , 35 , fill = WHITE , outline = BLACK , stroke = 2 )
71+ calc_display = Label (font , text = "0" , color = BLACK , max_glyphs = MAX_DIGITS )
72+ calc_display .y = 25
73+
74+ clear_button = add_button (0 , 0 , "AC" )
75+ add_button (1 , 0 , "+/-" )
76+ add_button (2 , 0 , "%" )
77+ add_button (3 , 0 , "/" , 1 , ORANGE , WHITE )
78+ add_button (0 , 1 , "7" )
79+ add_button (1 , 1 , "8" )
80+ add_button (2 , 1 , "9" )
81+ add_button (3 , 1 , "x" , 1 , ORANGE , WHITE )
82+ add_button (0 , 2 , "4" )
83+ add_button (1 , 2 , "5" )
84+ add_button (2 , 2 , "6" )
85+ add_button (3 , 2 , "-" , 1 , ORANGE , WHITE )
86+ add_button (0 , 3 , "1" )
87+ add_button (1 , 3 , "2" )
88+ add_button (2 , 3 , "3" )
89+ add_button (3 , 3 , "+" , 1 , ORANGE , WHITE )
90+ add_button (0 , 4 , "0" , 2 )
91+ add_button (2 , 4 , "." )
92+ add_button (3 , 4 , "=" , 1 , ORANGE , WHITE )
93+
9494# Add the display and buttons to the main calc group
9595calc_group .append (border )
9696calc_group .append (calc_display )
0 commit comments