0

I'm working on my very first python GUI, and I want to close all the previous windows from the code after clicking on the 'OK' button of the Message

messagebox.showinfo('Access Granted', 'Your data has been retrieved.')
  • By "*want to close all the previous windows*" - what did you mean? Do you want to terminate the program? Or do you want the root window to be opened and everything else to be closed? – Partho63 Apr 17 '19 at 06:36

2 Answers2

1

The tkinter dialogs return a string representing what the user clicked on, so it's just a matter of saving that value and checking it afterwards. However, since showinfo only gives the user one option it's always going to return "ok", so there's no need to check the value. Just call your function after the dialog has been displayed:

def some_function():
    messagebox.showinfo('Access Granted', 'Your data has been retrieved.')
    root.destroy()
...
button = tk.Button(root, text="Quit", command=some_function)
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
-1

So, say if your window was called root you would want to first define a function to 'destroy' the window

def closeWindow():
    root.destroy()

Then you'd want to add that command to the button -

btn = tkinter.Button(text="Click Me!" command=closeWindow)

If you get any more errors, let me know!

CodingGuy
  • 71
  • 7