Чтобы уменьшить утомительное кодирование, вы можете сделать что-то вроде этого:
valid_hystInt = lambda self, low, high: (
self.hystInt.get().isdigit() and (low <= int(self.hystInt.get()) <= high)
)
class Class:
hystInt = HystInt() # or whatever
def some_method(self):
if valid_hystInt(self, 200, 500):
pass # use it
или, возможно, даже более общее:
valid_int_field = lambda field, low, high: (
field.get().isdigit() and (low <= int(field.get()) <= high)
)
class Class:
hystInt = HystInt() # or whatever
def some_method(self):
if valid_int_field(self.hystInt, 200, 500):
pass # use it