0

I am working with a GUI and I'm trying to get the user input to only be an integer and an error label needs to show if it is blank or not an integer. I know the code below isn't right but I've been toying with different methods I'm reading and I can't seem to put something together that makes sense. At one point the error label was showing whenever I pressed the save button no matter what was put and then when I tried string values I got the error that's listed below the code. Please let me know if you have an idea or need more information. Thank you!

def minutes():
        while len(self.sideAuto.get()) == 0:
            try:
                self.sideAuto = int(input())
            except ValueError:
                ttk.Label(self, text="Must be valid integer.").grid(column=2, row=2, sticky=tk.E)

Exception in Tkinter callback

Traceback (most recent call last):
  File "C:\Users\jenna\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 537, in get
    return self._tk.getint(value)
_tkinter.TclError: expected integer but got "x"
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Jenna
  • 1
  • 2
  • I can't tell anything form this error message until you show me a proper working code. https://stackoverflow.com/help/minimal-reproducible-example – JacksonPro Dec 15 '20 at 15:15
  • I don't remember what code caused that error, I was just using it to say that when I enter x I want the error label to show but it didn't, just said it expected something else. I can't get a code to work for this. I'm sorry I tried to explain it. – Jenna Dec 15 '20 at 15:21
  • What you need is called `validation`. Just google it, there are plenty of questions here on the site too. – Delrius Euphoria Dec 15 '20 at 15:54

0 Answers0