0

I've seen that cool solution to my problem https://stackoverflow.com/a/42862728/17708836

I can't understand how i can define my own textvariable.

I modified it a bit. But in the original there will be the same problem. Custom classes which depend on other classes, too complicated for me

class digital_input(ttk.Entry):
    '''A Entry widget that only accepts digits'''
    def __init__(self, master=None, **kwargs):
        self.var = tk.StringVar(master)
        self.var.trace('w', self.validate)
        ttk.Entry.__init__(self, master, textvariable=self.var, **kwargs)
        self.get, self.set = self.var.get, self.var.set

    def validate(self, *args):
        value = self.get()
        if value == "":return
        if value[0] == '-':
            value = value[1:]
            if not value.isdigit():
                self.set("-" + ''.join(x for x in value if x.isdigit()))
        else:
            if not value.isdigit():
                self.set(''.join(x for x in value if x.isdigit()))

localid2_entry = digital_input(Frame, textvariable=offset_x_String_var)
localid2_entry.pack()

I've got that error.

ttk.Entry.__init__(self, master, textvariable=self.var, **kwargs)
    TypeError: tkinter.ttk.Entry.__init__() got multiple values for keyword argument 'textvariable'

I understand, that i have textvariable in digital_input __init__, and i try to add another textvariable by digital_input(Frame, textvariable=offset_x_String_var) and there is problem.

I can't figure out how to combine them.

And i can't understand what master=None do at that code. Why None if i can pass it in arguments like: Frame

Oh. I don't have 50 reputation, so i need to post my question there.

Michael Butscher
  • 10,028
  • 4
  • 24
  • 25

0 Answers0