Python 3 Tkinter-具有顶级管理员权限的消息框? [英] Python 3 Tkinter - Messagebox with a toplevel as master?

查看:219
本文介绍了Python 3 Tkinter-具有顶级管理员权限的消息框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,当顶层窗口小部件调用消息框对话框(例如"showinfo")时,根窗口将显示在顶层之上.有没有一种方法可以将顶级"窗口设置为消息框对话框的主窗口?

I've found that when a toplevel widget calls a messagebox dialog (like "showinfo"), the root window is showed up, over the toplevel. Is there a way to set the Toplevel window as the master of the messagebox dialog ?

这里是一个重现此内容的脚本:

Here is a script to reproduce this :

# -*- 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:

You can set the parent argument to topWindow for the showInfo command:

Button(..., command=lambda: messagebox.showInfo(parent=topWindow, ...))

另请参阅:

这篇关于Python 3 Tkinter-具有顶级管理员权限的消息框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆