英文:
Could be closed tkinter simpledialog askinteger after 30 seconds? I need to use simpledialog
问题
My case:
我需要使用simpledialog来向Python代码输入数据。我的代码如下:
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
如果用户在30秒内未输入整数,simpledialog窗口将被关闭,并从kw.txt中获取数据。
我需要使用simpledialog。
英文:
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.
答案1
得分: 0
你可以使用after()
来安排一个函数的执行。所以,像这样做。
def enter_plan_week():
root = tk.Tk()
root.withdraw()
root.after(30*1000, root.destroy)
value = simpledialog.askinteger(title="iiiiiii", prompt="nnnnnnnnnnn")
...
return kw
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论