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()
    window2.geometry("500x500")
    def message():
        tkinter.messagebox.showinfo("message", "test")
    button2 = tkinter.Button(window2, text = "messagebox", command = message)
    button2.pack()
window1 = tkinter.Tk()
window1.geometry("500x500")
button = tkinter.Button(window1, text = "next", command = next_window)
button.pack()

tkinter.mainloop()

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:
https://tkdocs.com/shipman/focus.html
so you could experiment with using those instead of clicking on the
window.

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:
https://tkdocs.com/shipman/toplevel.html
I’d expect that to shuffle the stacking order without changing the
focus. Untested.

Cheers,
Cameron Simpson cs@cskk.id.au