Messagebox switching window placement

hi guys, when message bo is clicked it makes window1 go in front of window2, not a big deal but is there anyway to keep window 2 in front? I’ve tried withdraw but it deletes the window instead

import tkinter
from tkinter import messagebox
def next_window(): 
    window2 = tkinter.Toplevel()
    def message():
        tkinter.messagebox.showinfo("message", "test")
    button2 = tkinter.Button(window2, text = "messagebox", command = message)
window1 = tkinter.Tk()
button = tkinter.Button(window1, text = "next", command = next_window)


Unfortunately, to a large extend this is an artifact not of the widget
kit (tkinter) but of your desktop’s window management policies.

On some desktop it is policy that the window with the focus is on top.
And/or, separately, that clicking on a window brings it to the front
(and gives it focus).

tkinter has specific focus methods:
so you could experiment with using those instead of clicking on the

Alternatively, if your objective is that window 2 is always above window
1 you might notice window 1 getting focus and use the .lift() method
on window 2 to bring it in front of window 1:
I’d expect that to shuffle the stacking order without changing the
focus. Untested.

Cameron Simpson