Вопрос

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