Frage

import tkinter.messagebox
a = tkinter.messagebox.askquestion('','hi')

After the 'askquestion' window closes the tkinter window still remains.

I can resolve this by the following:

import tkinter.messagebox
top = tkinter.Tk()
a = tkinter.messagebox.askquestion('','hi')
top.destroy()

This destroys the window.

My question is:

Is there a way to destroy the window without creating a reference to it?

I tried:

import tkinter.messagebox
a = tkinter.messagebox.askquestion('','hi')
tkinter.Tk().destroy()

but that has no effect.

War es hilfreich?

Lösung

If you destroy the root window, Tkinter try to recreate one when you call askquestion.

Don't destory the root window. Instead use withdraw.

import tkinter.messagebox
tkinter.Tk().withdraw()
a=tkinter.messagebox.askquestion('','hi')
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top