【问题标题】:How to get tkinter messagebox to appear in front of toplevel如何让 tkinter 消息框出现在顶层前面
【发布时间】:2016-07-16 06:55:08
【问题描述】:

我正在使用 Python 3 和 tkinter 编写一个程序,其中顶层最​​初显示在根窗口的中心。如果顶层没有移开,它会覆盖任何可能出现以显示错误消息的消息框。消息框出现在根窗口的前面,但在顶层后面。从命令行显示发生了什么的简单示例:

>>> 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?')

有没有办法让消息框出现在顶层前面?

【问题讨论】:

  • 在我的 Mac 上按预期工作,您使用的是什么操作系统?
  • 您是否尝试过让消息框成为顶层的子级?
  • 我使用的是 Linux Mint 17.3。我不确定如何使消息框成为顶层的子级。我试过了,但没有用:>>> mess = messagebox.showinfo(texto, message='Does this work?')消息框仍然出现在顶层下方。
  • messagebox.showinfo("title", "message",master=texto) 将是您将其指定为texto 的子项的方式
  • 稍作修改(messagebox.showinfo(message='Does this work'), master=texto),它确实有效!只需将您的评论变成答案,我会接受它。:o)

标签: tkinter


【解决方案1】:

我尝试使用“父级”而不是主控 Messagebox with top level as Master 它对我有用!

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多