Search code examples
pythongtk3glade

How do I set a invisible default value in entry widgets?


I'm making a small app with Gtk3 and Glade that calculates volumes, it has a lot of entry widgets and for calculation purposes I need them to be set to 0 by default. That's easily done in Glade but I want the 0 to be invisible.

Is there a way to make the default value of the entry invisible or to apply a conditional like:

if entry = None:
    entry = 0

to all the entry widgets without repeating myself endlessly?


Solution

  • I decided on implementing the decimal module instead of using floats, I then wrote a small function to check for input.

    def num(entry):
        number = Decimal(0.00) if not entry else Decimal(entry)
        return number
    

    Works fine and seems like the best solution. At least that's what I'm going for.