0
votes

Basically, here is the problem

All of the user interface is within a tkinter message box. I have a program which the user inputs a string into a variable. String is checked if it is an integer. If yes; print this is an int, if no, launch another message box with a warning message, and an 'ok' button will be displayed.

This is the problem

I have written the code for the whole thing so far, below is the code for the warning message box:

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()

When the 'ok' button is pressed, the warning window closes, but when I re enter the values, and press the enter button again, it runs through the integer checker, then goes to deploy the warning message, and fails......

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

I don't know why it doesn't want to launch that same message box again... It might have something to do with the 'Application has been destroyed'....

If anyone could help, that would be very useful

1
Do you realize that you're trying to keep using an application after you've destroyed it? I suggest you look for a tutorial on how to properly set up Tkinter applications. - TigerhawkT3
That was an attempt to close the window, it doesn't work..... It terminates the code there.... Do you know a way of closing a tkinter window without terminating that piece of code or the entire program? I think that's what I need.... - Daniel Morris

1 Answers

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