Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge the two validating functions by using a callback which accepts keyword arguments #4

Open
ghost opened this issue Feb 7, 2019 · 1 comment

Comments

@ghost
Copy link

ghost commented Feb 7, 2019

The two validating functions could be merged two one dynamic validating function which accepts a keyword (e.g. called "floattype") so that depending on value of that keyword argument a different regex is compiled.

See this PSEUDO-CODE:

def validate_input(self,name,index,mode,floattype=None):

    if floattype == "unit interval":
        regex = re.compile(r'^0(\.[0-9]*)?$|^1(\.0?)?$|^$')
    regex = re.compile(r'^[+-]?((\d+\.?\d*)|(\.\d+))$|^$')

    for var in self.input_vars:
        if name == str(var):
            if not regex.match(var.get()):
                var.set(var.get()[:-1])
                self.master.bell()

See also these stackoverflow-posts:

Pass Multiple Arguments to Callback for a StringVar in Tkinter
How can I pass arguments to Tkinter button's callback command?

@ghost
Copy link
Author

ghost commented Feb 7, 2019

On the other hand I don't really find the suggested methods in the stackoverflow-posts readable, so it could also be a trade-off question (readability vs. length of code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants