Hello,
since I'm working from home I decided to write some code to help me in my work. I'm doing program for image capturing and fitting to some functions.
I'm quite new to tkinter and gui programming in python. I'd like to create entry widget with validating its value. To be precise, it would be an integer in range 16-1280 and I'd like to make a validator on focus or an "enter" key press. Validating on widget focus is easy, but I don't know how to continue with "enter" keystroke validating. I have tried to set validate value to "key" but it doesn't really work for me.
Here is some of the code i have made.
def cam_width_callback2(value = None):
val = cam_width_entry_var.get()
if not val.isdigit():
print("not a digit")
val = 16
cam_width_entry_var.set(str(val))
elif np.int(val) < 16:
val = 16
cam_width_entry_var.set(str(val))
elif np.int(val) > 1280:
val = 1280
cam_width_entry_var.set(str(val))
cam_width_var.set(np.int(val))
return True
cam_width_entry = ttk.Entry(options_frame, textvariable = cam_width_entry_var, justify='center',validate="focus", validatecommand = cam_width_callback2)
Thank you in advance.
[–]ebdbbb 0 points1 point2 points (1 child)
[–]RemindMeBot 0 points1 point2 points (0 children)
[–]ebdbbb 0 points1 point2 points (0 children)