Nov-16-2019, 09:03 PM
I'm trying to get this data validation to work. It seems to work ok when checking, but it just does some funny things, that I don't understand. First, here is the code:
Then, how can I reset the validation check? the %P seems to retain the values, and it triggers the checks more than once. Not sure if I'm explaining this well, but for some reason I tend to get my messageboxes popping up more than once.
Thanks.
import tkinter as tk from tkinter import messagebox class Example(tk.Frame): def __init__(self, parent): tk.Frame.__init__(self, parent) l_focus = self.register(self.leave_field) self.entry1 = tk.Entry(self) self.entry2 = tk.Entry(self) self.entry3 = tk.Entry(self) self.entry1.configure(validate="focusout", validatecommand=(l_focus, '%P')) self.entry2.configure(validate="focusout", validatecommand=(l_focus, '%P')) self.entry3.configure(validate="focusout", validatecommand=(l_focus, '%P')) self.entry1.pack(side="top", fill="x") self.entry2.pack(side="top", fill="x") self.entry3.pack(side="top", fill="x") def leave_field(self, inp): if inp == "": messagebox.showinfo("Blank Entry", "You must enter a number.") return False else: # Check entry is Number try: float(inp) if int(inp) < 10 or int(inp) > 15: messagebox.showinfo("Out of Range", inp + " is not between 10-15") return False else: return True except ValueError: messagebox.showinfo("Not Numeric", inp + " is not a valid number.") return FalseSo first off, if the first textbox is erroneous, my messagebox pops up, I click ok, and then I have to click back on the textbox to fix the error. Well, this triggers the next textbox's validation check, and it shows empty. Is there a way that I can when I click OK on the message box, the erroneous entry retains focus?
Then, how can I reset the validation check? the %P seems to retain the values, and it triggers the checks more than once. Not sure if I'm explaining this well, but for some reason I tend to get my messageboxes popping up more than once.
Thanks.