2015-10-05 250 views
0

基本上,這是問題可重複的tkinter按鈕命令...?

所有的用戶界面都在tkinter消息框內。 我有一個程序,用戶輸入一個字符串到一個變量。檢查字符串是否是整數。如是;打印這是一個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

我不知道爲什麼它不想再次啓動同一個消息框......它可能與「應用程序已被銷燬」有關......

如果有人可以幫助,這將是非常有用的

+0

你是否意識到,你試圖繼續使用應用程序後,你已經摧毀了它?我建議你看看如何正確設置Tkinter應用程序的教程。 – TigerhawkT3

+0

這是試圖關閉窗口,它不起作用.....它終止代碼....你知道關閉tkinter窗口的一種方式,而不終止那段代碼或整個程序?我認爲這就是我需要的...... –

回答

0
import tkSimpleDialog 
result = tkSimpleDialog.askinteger(title, prompt [,options]) 
+0

請給你的答案添加一些解釋! –

+0

這種批評是迂腐的廢話。任何人都可以閱讀,誰能夠在最基本的水平上進行編程,都可以理解我的回答如何回答OP的問題。你只是想讓我添加一些毫無貢獻的空話。 – saulspatz