My case: I need input data by simpledialog to python code. My code is:
def enter_plan_week():
root = tk.Tk()
root.withdraw()
value = simpledialog.askinteger(title="iiiiiii",prompt="nnnnnnnnnnn")
if value is not None:
kw = value
open('kw.txt', 'w').write(str(kw))
else:
kw = int(open('kw.txt', 'r').read())
return kw
If user no enter integer after 30 seconds simpledialog window should be closed and take data from kw.txt. I need to use simpledialog.
You can schedule a function with the after()
. So, do like this.
def enter_plan_week():
root = tk.Tk()
root.withdraw()
root.after(30*1000, root.destroy)
value = simpledialog.askinteger(title="iiiiiii",prompt="nnnnnnnnnnn")
...
return kw