Why do I get a DoubleVar has no attribute _report_exception
error when trying to define a custom tkinter entry widget that accepts only floats?
It happens when I delete the contents of the entry widget to enter a new floating point number
I've tried to follow the example taken from the documentation here except for changing tk.StringVar() to tk.DoubleVar() they look to be identical..
example of using custom entry widget:
self.depth_label = tk.Label(self, text="Maximum Depth")
self.depth_label.grid(row=1, column = 1)
self.depth_entry = FloatEntry(self, default=255.0)
self.depth_entry.grid(row=1, column = 2)
custom entry class
class FloatEntry(tk.Entry):
def __init__(self, master, default=0.0, **kwargs):
tk.Entry.__init__(self, master, **kwargs)
self.default = default
self.value = self.default
self.float = tk.DoubleVar()
self.float.set(self.value)
self.float.trace("w", self.__callback)
self.config(textvariable=self.float)
def __callback(self, *dummy):
value = self.float.get()
new_value = self.validate(value)
if new_value is None:
self.float.set(self.default)
elif new_value != value:
self.value = new_value
self.float.set(self.new_value)
else:
self.value = value
def validate(self, value):
try:
if value:
value = float(value)
return value
except ValueError:
return None