基本上,问题是这样的。
所有的用户界面都在tkinter消息框中。我有一个程序,用户输入一个字符串到一个变量。如果字符串是整数,则对其进行检查。如果是,则打印这是一个整数;如果不是,则启动另一个带有警告消息的消息框,并显示“确定”按钮。
这就是问题所在
到目前为止,我已经编写了整个代码,以下是警告消息框的代码:
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
我不知道为什么它不想再次打开同样的消息框...这可能与“应用程序已被销毁”有关……
如果有人能帮上忙,那将是非常有用的
发布于 2015-10-07 06:04:57
import tkSimpleDialog
result = tkSimpleDialog.askinteger(title, prompt [,options])
https://stackoverflow.com/questions/32945369
复制