4

I am using python 3. If I opan an error messagebox, i get two frames, one is emty and one is the error-window. That is my code:

from tkinter import messagebox

messagebox.showwarning('warning', 'warning')
user8400839
  • 105
  • 1
  • 9
  • Does this answer your question? [Tkinter messagebox without window?](https://stackoverflow.com/questions/17280637/tkinter-messagebox-without-window) – Michael Litvin Jun 30 '21 at 12:11

3 Answers3

2

Everything works correctly in your example. The empty window is the main window of Tk. It is always open when you start any Tk program. You can minimize it if you want, but closing it terminates the main loop.

DYZ
  • 55,249
  • 10
  • 64
  • 93
1

Try this:

  root = tkinter.Tk()
  root.withdraw()
  messagebox.showwarning('warning', 'warning')
Ameneh Sh
  • 11
  • 2
0

Thank you DYZ, in my code is no main window, (eg.: main = Tk() ... main.mainloop), because of that the warning massage create one. I could solve the problem by create one and minimize it. at the end of massagebox I destroyed it to continue in code.

from tkinter import *

from tkinter import messagebox

main = Tk()
main.geometry("500x400+300+300")
def message():
  main.geometry("0x0")
  messagebox.showwarning("Say Hello", "Hello World")
  main.destroy()
B1 = Button(main, text = "Start Dialog",fg="dark green", command = message)
B1.pack()

main.mainloop()

print("finish dialog")
user8400839
  • 105
  • 1
  • 9