可重复的tkinter按钮命令。。。?

2024-04-25 00:52:03 发布

您现在位置:Python中文网/ 问答频道 /正文

基本上,这就是问题所在

所有的用户界面都在一个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

我不知道为什么它不想再次启动相同的消息框。。。它可能与“应用程序已被销毁”。。。。你知道吗

如果有人能帮忙,那将非常有用


Tags: 字符串代码text消息警告timedef整数