我发现当一个顶层小部件调用一个消息框对话框(比如“showinfo”)时,根窗口就会显示在顶层之上。有没有办法将顶层窗口设置为消息框对话框的主窗口?
下面是一个脚本来重现这一点:
# -*- coding:utf-8 -*-
# PYTHON 3 ONLY
from tkinter import *
from tkinter import messagebox
root = Tk()
root.title('ROOT WINDOW')
Label(root, text = 'Place the toplevel window over the root window\nThen, push the button and you will see that the root window is again over the toplevel').grid()
topWindow = Toplevel(root)
topWindow.title('TOPLEVEL WINDOW')
Label(topWindow, text = 'This button will open a messagebox but will\ndo a "focus_force()" thing on the root window').grid()
Button(topWindow, text = '[Push me !]', command = lambda: messagebox.showinfo('foo', 'bar!')).grid()
# --
root.mainloop()
可以为
showInfo
命令将parent
参数设置为topWindow
:另见:
这可能会解决更多当前版本的问题。
相关问题 更多 >
编程相关推荐