3

I am trying to make my messagebox appear in front of my pygame window, but it keeps appearing behind it. Here's my code:

from tkinter import messagebox

# pygame loop here
messagebox.showinfo("Title", "Message here")

Do I need to do add some lines of code to bring it to the front? Any help would be appreciated.

o.o
  • 3,563
  • 9
  • 42
  • 71

2 Answers2

4

I got it to work. I had to add root.withdraw() as well.

import tkinter as tk
from tkinter import messagebox

root = tk.Tk()
root.withdraw()

# pygame loop here
messagebox.showinfo("Title", "Message here")
root.lift()

Not sure why hiding the root tkinter window makes it work...

o.o
  • 3,563
  • 9
  • 42
  • 71
0

This will put the window in the middle of the screen on the top level of everything, so it will not be hidden behind and stays in front.

window = Tk()
window.eval('tk::PlaceWindow %s center' % window.winfo_toplevel())
Jaroslav Bezděk
  • 6,967
  • 6
  • 29
  • 46
VPraharsha
  • 386
  • 2
  • 8