From f600c353167e5bac5076c4c0e9b82d39ce26077a Mon Sep 17 00:00:00 2001 From: emkael Date: Sun, 13 Mar 2022 12:35:16 +0100 Subject: Float number type of GUI variable --- jfr_playoff/gui/variables.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/jfr_playoff/gui/variables.py b/jfr_playoff/gui/variables.py index e76f503..d72f22e 100644 --- a/jfr_playoff/gui/variables.py +++ b/jfr_playoff/gui/variables.py @@ -13,6 +13,13 @@ class NotifyVar(tk.Variable): self._root.event_generate('<>', when='tail') self._prevValue = self.get() +class FloatVar(tk.StringVar): + def get(self, default=None): + try: + return float(str(tk.StringVar.get(self)).strip()) + except ValueError: + return default + class NumericVar(tk.StringVar): def get(self, default=None): try: @@ -45,3 +52,8 @@ class NotifyNumericVar(NumericVar, NotifyVar): def __init__(self, *args, **kwargs): NotifyVar.__init__(self, *args, **kwargs) NumericVar.__init__(self, *args, **kwargs) + +class NotifyFloatVar(FloatVar, NotifyVar): + def __init__(self, *args, **kwargs): + NotifyVar.__init__(self, *args, **kwargs) + FloatVar.__init__(self, *args, **kwargs) -- cgit v1.2.3