문제

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.

도움이 되었습니까?

해결책

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')
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top