【发布时间】:2015-10-07 14:04:57
【问题描述】:
基本上,这就是问题所在
所有的用户界面都在一个 tkinter 消息框中。 我有一个程序,用户将字符串输入到变量中。检查字符串是否为整数。如果是; print this is an int,如果不是,则启动另一个带有警告消息的消息框,并会显示一个“确定”按钮。
这就是问题
到目前为止,我已经编写了整个代码,下面是警告消息框的代码:
from Tkinter import *
__author__ = 'Super'
def close_program():
root.destroy()
def number_checker():
global vehicle_distance
global vehicle_time
try:
vehicle_distance = float(vehicle_distance)
correct_text_distance()
except ValueError:
failed_text_distance()
try:
vehicle_time = float(vehicle_time)
correct_text_time()
except ValueError:
failed_text_time()
def failed_text_time():
global root
root = Tk()
root.title("Fatal Error")
root.geometry("300x30")
error_label = Label(root, text="Please input an integer for the field 'time'")
error_label.pack()
ok_button = Button(root, text="Ok", command=close_program)
ok_button.pack()
root.mainloop()
按下“确定”按钮时,警告窗口会关闭,但是当我重新输入值并再次按下回车按钮时,它会运行整数检查器,然后去部署警告消息,但失败了。 .....
File "C:\Python27\lib\lib-tk\Tkinter.py", line 2036, in __init__
(widgetName, self._w) + extra + self._options(cnf))
TclError: can't invoke "label" command: application has been destroyed
我不知道为什么它不想再次启动同一个消息框...这可能与“应用程序已被销毁”有关...。
如果有人可以提供帮助,那将非常有用
【问题讨论】:
-
您是否意识到您在销毁应用程序后仍试图继续使用它?我建议您查找有关如何正确设置 Tkinter 应用程序的教程。
-
那是试图关闭窗口,它不起作用.....它终止了那里的代码......你知道在不终止该片段的情况下关闭 tkinter 窗口的方法吗代码还是整个程序?我想这就是我需要的......
标签: python python-2.7 user-interface tkinter messagebox