'How to get tkinter messagebox to appear in front of toplevel

I'm writing a program with Python 3 and tkinter in which toplevels initially appear centered in the root window. If a toplevel isn't moved out of the way, it covers up any messagebox that may arise to display an error message. The messagebox appears in front of the root window, but behind the toplevel. Simple example from the command line to show what happens:

>>> from tkinter import *
>>> from tkinter import messagebox
>>> root = Tk()
>>> texto = Toplevel(root) # (Manually put toplevel in front of root)
>>> messagebox.showinfo(message='Does this work?')

Is there a way to get the messagebox to appear in front of the toplevel?



Solution 1:[1]

Instead of master I tried by using: "parent" as this one Messagebox with top level as Master and it worked for me!

messagebox.showinfo("title", "message",parent=texto)

Solution 2:[2]

Just define the parent of messagebox

messagebox.showinfo(parent=textto, message="blah")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cecilia Barboza
Solution 2 Jessie Wilson