@@ -78,64 +78,56 @@ def __init__(self):
7878 self .tips .set_tips (self .add_value_button , 'Add values you have entered in the input fields to the register.' )
7979 self .tips .set_tips (self .make_pie_chart_button , 'Generate a pie-chart according to the data provided by you.' )
8080
81- self .item_entry .bind ('<FocusIn>' , self .bindings )
82- self .value_entry .bind ('<FocusIn>' , self .bindings )
83- self .value_entry .bind ('<FocusOut>' , lambda event , focus_out = True : self .bindings (event , focus_out ))
84-
8581 self .master .after (0 , lambda : include .initial_position (self .master , 'Pie Chart Creator' ))
8682 self .master .protocol ('WM_DELETE_WINDOW' , self .exit )
87- self .master .bind ('<Button-1>' , self .bindings )
83+ self .master .bind ('<Button-1>' , self .master_bindings )
84+ self .item_entry .bind ('<FocusIn>' , self .entry_bindings )
85+ self .value_entry .bind ('<FocusIn>' , self .entry_bindings )
86+ self .explode_radio_button_enable .bind ('<FocusIn>' , self .entry_bindings )
87+
8888 self .container_frame .pack ()
8989 self .master .mainloop ()
9090
91- def config (self , widget = None , mode = None , text = None , color = None , styles = None ):
92- '''Behaviour for the entry boxes when user gets in and out of them '''
93-
94- if widget :
95- widget .delete (0 , tix .END )
96-
97- if mode == 'insert' :
98- widget .insert (tix .END , text )
99-
100- if widget == self .value_entry and self .item_entry .get () == 'Items' :
101- self .items_style .configure ('I.TEntry' , foreground = 'grey' )
102-
103- styles [0 ].configure (styles [1 ], foreground = color )
91+ def master_bindings (self , event = None ):
92+ '''When user clicks anywhere outside of entry boxes and buttons'''
10493
105- def bindings (self , event , focus_out = False ):
106- '''When user clicks in and out of the entries widgets'''
94+ widget = event .widget
95+ widgets = [self .item_entry , self .value_entry ]
96+ entries_widgets = {self .item_entry : 'Items' , self .value_entry : 'Values' }
97+ entries_styles = {self .item_entry : (self .items_style , 'I.TEntry' ), self .value_entry : (self .value_style , 'V.TEntry' )}
10798
108- widgets = {self .item_entry : 'Items' , self .value_entry : 'Values' }
99+ for wid in entries_widgets :
100+ if not wid .get ().strip ():
101+ wid .delete (0 , tix .END )
102+ wid .insert (tix .END , entries_widgets [wid ])
103+ style , style_name = entries_styles [wid ]
104+ style .configure (style_name , foreground = 'grey' )
109105
110- if event .widget == self .item_entry :
111- styles = (self .items_style , 'I.TEntry' )
112-
113- else :
114- styles = (self .value_style , 'V.TEntry' )
115-
116- for widget , text in widgets .items ():
117- if widget == event .widget :
118- if widget .get () == text :
119- self .config (widget , 'delete' , text , 'black' , styles )
120-
121- else :
122- if not widget .get ():
123- self .config (widget , 'insert' , text , 'grey' , styles )
106+ if widget not in widgets :
107+ self .master .focus ()
124108
125- if focus_out :
126- if not widget .get ():
127- self .config (widget , 'insert' , text , 'grey' , styles )
109+ def entry_bindings (self , event = None ):
110+ '''When user clicks in or out of the entries widget'''
128111
129- if event .widget not in widgets :
130- _styles = [(self .items_style , 'I.TEntry' ), (self .value_style , 'V.TEntry' )]
112+ widget = event .widget
113+ entries_widgets = {self .item_entry : 'Items' , self .value_entry : 'Values' }
114+ entries_styles = {self .item_entry : (self .items_style , 'I.TEntry' ), self .value_entry : (self .value_style , 'V.TEntry' )}
131115
132- for index , widget in enumerate (widgets .items ()):
133- wid , text = widget
116+ if widget in entries_widgets :
117+ if widget .get ().strip () == entries_widgets [widget ]:
118+ widget .delete (0 , tix .END )
119+ style , style_name = entries_styles [widget ]
120+ style .configure (style_name , foreground = 'black' )
134121
135- if wid . get (). strip () == text :
136- self . config ( color = 'grey' , styles = _styles [ index ] )
122+ entries_widgets . pop ( widget )
123+ entries_styles . pop ( widget )
137124
138- self .master .focus ()
125+ for wid in entries_widgets :
126+ if not wid .get ().strip ():
127+ wid .delete (0 , tix .END )
128+ wid .insert (tix .END , entries_widgets [wid ])
129+ style , style_name = entries_styles [wid ]
130+ style .configure (style_name , foreground = 'grey' )
139131
140132 def exit (self ):
141133 '''When user clicks to X button in the title bar'''
0 commit comments