简体   繁体   中英

How to avoid error when user enters no input in a tkinter entry box?

Hi I am trying to get a solution for, if a user enters no value into an entry box, it doesn't create an error. i have tried:

if players_math_answer_var.get() is None or players_math_answer_var.get() == "":
    players_math_answer_var.set(0)

also tried to set the value to 0 when initializing tk variable

[![players_math_answer_var = tk.IntVar(value=0)][1]][1]

But still get this error message (See screen shot)

在此处输入图像描述

As I understand you want it to be impossible for errors to occur, so try the try - except statement

try : # do this 
    # .....
except : # if error happened do this 
    # .....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM