lift a tkMessageBox
-
02-07-2021 - |
質問
I am using tkMessageBox.showinfo (info at tutorialspoint) to popup warnings in my program.
The problem happens only when the warning is called with a second TopLevel window (apart from the main one) on screen: in this case the warning remains hidden behind the second TL window.
I tried to call it thus:
tkMessageBox.showinfo(title='Warning',message=s).lift()
but it doesnt work. Any ideas?
解決
I think the message box is only ever guaranteed to be above its parent. If you create a second toplevel and you want a messagebox to be on top of that second window, make that second window the parent of the messagebox.
tl2 = tk.Toplevel(...)
...
tkMessageBox.showinfo("Say Hello", "Hello World", parent=tl2)
他のヒント
I do not see the issue that you describe. The code I wrote below is just about the minimum needed to create a window which creates a second window. The second window creates an info box using the showinfo
method. I wonder whether you have something besides this. (Note that I made the windows somewhat large in order to attempt cover up the info window.)
from Tkinter import Tk, Button, Toplevel
import tkMessageBox
top = Tk()
def make_window():
t = Toplevel(top)
t.title("I'm Window 2. Look at me too!")
B2 = Button(t, text = "Click me", command = hello)
B2.pack()
t.geometry('500x500+50+50')
def hello():
tkMessageBox.showinfo("Say Hello", "Hello World")
B1 = Button(top, text = "New Window", command = make_window)
B1.pack()
top.title("I'm Window 1. Look at me!")
top.geometry('500x500+100+100')
top.mainloop()
This was tested on Windows 7 (64-bit) using Python 2.7 (32-bit). It produces something like this: