首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >可重复的tkinter按钮命令...?

可重复的tkinter按钮命令...?
EN

Stack Overflow用户
提问于 2015-10-05 17:37:23
回答 1查看 147关注 0票数 0

基本上,问题是这样的。

所有的用户界面都在tkinter消息框中。我有一个程序,用户输入一个字符串到一个变量。如果字符串是整数,则对其进行检查。如果是,则打印这是一个整数;如果不是,则启动另一个带有警告消息的消息框,并显示“确定”按钮。

这就是问题所在

到目前为止,我已经编写了整个代码,以下是警告消息框的代码:

代码语言:javascript
代码运行次数:0
运行
复制
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

我不知道为什么它不想再次打开同样的消息框...这可能与“应用程序已被销毁”有关……

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

EN

回答 1

Stack Overflow用户

发布于 2015-10-07 14:04:57

代码语言:javascript
代码运行次数:0
运行
复制
import tkSimpleDialog
result = tkSimpleDialog.askinteger(title, prompt [,options])
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32945369

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档