@@ -148,7 +148,7 @@ def _key_validate(self, proposed, action, **kwargs):
148148
149149    # get our values list 
150150    values  =  self .cget ('values' )
151-     # Do a case-insensitve  match against the entered text 
151+     # Do a case-insensitive  match against the entered text 
152152    matching  =  [
153153      x  for  x  in  values 
154154      if  x .lower ().startswith (proposed .lower ())
@@ -199,7 +199,7 @@ def _set_focus_update_var(self, event):
199199    if  self .focus_update_var  and  not  self .error .get ():
200200      self .focus_update_var .set (value )
201201
202-   def  _set_minimum (self , * args ):
202+   def  _set_minimum (self , * _ ):
203203    current  =  self .get ()
204204    try :
205205      new_min  =  self .min_var .get ()
@@ -212,7 +212,7 @@ def _set_minimum(self, *args):
212212      self .variable .set (current )
213213    self .trigger_focusout_validation ()
214214
215-   def  _set_maximum (self , * args ):
215+   def  _set_maximum (self , * _ ):
216216    current  =  self .get ()
217217    try :
218218      new_max  =  self .max_var .get ()
@@ -228,13 +228,13 @@ def _set_maximum(self, *args):
228228  def  _key_validate (
229229    self , char , index , current , proposed , action , ** kwargs 
230230  ):
231+     if  action  ==  '0' :
232+       return  True 
231233    valid  =  True 
232234    min_val  =  self .cget ('from' )
233235    max_val  =  self .cget ('to' )
234236    no_negative  =  min_val  >=  0 
235237    no_decimal  =  self .precision  >=  0 
236-     if  action  ==  '0' :
237-       return  True 
238238
239239    # First, filter out obviously invalid keystrokes 
240240    if  any ([
@@ -269,16 +269,17 @@ def _focusout_validate(self, **kwargs):
269269    max_val  =  self .cget ('to' )
270270
271271    try :
272-       value  =  Decimal (value )
272+       d_value  =  Decimal (value )
273273    except  InvalidOperation :
274-       self .error .set ('Invalid number string: {}'  . format ( value ) )
274+       self .error .set (f 'Invalid number string: { value } '  )
275275      return  False 
276276
277-     if  value  <  min_val :
278-       self .error .set ('Value is too low (min {})' .format (min_val ))
277+     if  d_value  <  min_val :
278+       self .error .set (f'Value is too low (min { min_val }  )' )
279+       valid  =  False 
280+     if  d_value  >  max_val :
281+       self .error .set (f'Value is too high (max { max_val }  )' )
279282      valid  =  False 
280-     if  value  >  max_val :
281-       self .error .set ('Value is too high (max {})' .format (max_val ))
282283
283284    return  valid 
284285
@@ -288,36 +289,23 @@ class BoundText(tk.Text):
288289  def  __init__ (self , * args , textvariable = None , ** kwargs ):
289290    super ().__init__ (* args , ** kwargs )
290291    self ._variable  =  textvariable 
291-     self ._modifying  =  False 
292292    if  self ._variable :
293293      # insert any default value 
294294      self .insert ('1.0' , self ._variable .get ())
295295      self ._variable .trace_add ('write' , self ._set_content )
296296      self .bind ('<<Modified>>' , self ._set_var )
297297
298-   def  _clear_modified_flag (self ):
299-     # This also triggers a '<<Modified>>' Event 
300-     self .tk .call (self ._w , 'edit' , 'modified' , 0 )
301- 
302298  def  _set_var (self , * _ ):
303299    """Set the variable to the text contents""" 
304-     if  self ._modifying :
305-       return 
306-     self ._modifying  =  True 
307-     # remove trailing newline from content 
308-     content  =  self .get ('1.0' , tk .END )[:- 1 ]
309-     self ._variable .set (content )
310-     self ._clear_modified_flag ()
311-     self ._modifying  =  False 
300+     if  self .edit_modified ():
301+       content  =  self .get ('1.0' , 'end-1chars' )
302+       self ._variable .set (content )
303+       self .edit_modified (False )
312304
313305  def  _set_content (self , * _ ):
314306    """Set the text contents to the variable""" 
315-     if  self ._modifying :
316-       return 
317-     self ._modifying  =  True 
318307    self .delete ('1.0' , tk .END )
319308    self .insert ('1.0' , self ._variable .get ())
320-     self ._modifying  =  False 
321309
322310################## 
323311# Module Classes # 
@@ -595,7 +583,9 @@ def reset(self):
595583      plot  =  self ._vars ['Plot' ].get ()
596584    except  tk .TclError :
597585      plot  =  '' 
598-     plot_values  =  self ._vars ['Plot' ].label_widget .input .cget ('values' )
586+     plot_values  =  (
587+       self ._vars ['Plot' ].label_widget .input .cget ('values' )
588+     )
599589
600590    # clear all values 
601591    for  var  in  self ._vars .values ():
0 commit comments