打开tkinter message框,该消息框在屏幕的右下角而不是中心

发布于 2025-02-08 08:00:01 字数 1360 浏览 1 评论 0原文

MessageBox默认情况下在屏幕中心打开:

”在此处输入图像说明“

,但我希望它在屏幕右下方打开:

我的原始代码:

from tkinter import Tk
from tkinter.messagebox import Message 
from _tkinter import TclError

TIME_TO_WAIT = 1000
root = Tk()
root.withdraw()
try:
    root.after(TIME_TO_WAIT, root.destroy) 
    Message(title="Visual Studio Code", message="New Match Found", master=root).show()
except TclError:
    pass

按照指示,我尝试使用root.geometry,但意识到它不适用于MessageBox,仅适用于标准框:

root = Tk()
x = 1000
y = -1000
root.geometry(f'250x150+{x}+{y}')
root.withdraw()

# rest of code...

打印专用于 claudio的答案(以帮助了解我们的辩论):

“

The messagebox by default opens in the center of the screen:

enter image description here

But I would like it to open at the bottom right of the screen:

enter image description here

My original code:

from tkinter import Tk
from tkinter.messagebox import Message 
from _tkinter import TclError

TIME_TO_WAIT = 1000
root = Tk()
root.withdraw()
try:
    root.after(TIME_TO_WAIT, root.destroy) 
    Message(title="Visual Studio Code", message="New Match Found", master=root).show()
except TclError:
    pass

As per indications, I tried using root.geometry but realized that it doesn't work for messagebox, only for standard box:

root = Tk()
x = 1000
y = -1000
root.geometry(f'250x150+{x}+{y}')
root.withdraw()

# rest of code...

Prints dedicated to Claudio's answer (to help understand our debate):

enter image description here

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回忆躺在深渊里 2025-02-15 08:00:01

下面的代码在我的系统上工作,显示了显示屏右下角的消息框。 “窍门”是MessageBox在父窗口上摇摆,因此root.nemetry()的适当设置会导致它出现在将根窗口放在屏幕上的地方。您已经自己找到了它,但是root.withdraw()阻止了消息框的预期放置:

from tkinter import Tk
from tkinter.messagebox import Message 

TIME_TO_WAIT = 3000

root = Tk()
root.geometry(f'100x100+{root.winfo_screenwidth()-100}+{root.winfo_screenheight()-100}')
root.after(TIME_TO_WAIT, root.destroy)
Message(title="Visual Studio Code", message="New Match Found", master=root).show()

The code below works on my system displaying the message box in the right bottom corner of the display. The 'trick' is that the messagebox hoovers over the parent window, so the appropriate setting of root.geometry() causes it to appear where the root window is placed on the screen. You have found it out by yourself already, but the root.withdraw() prevented the expected placement of the messagebox:

from tkinter import Tk
from tkinter.messagebox import Message 

TIME_TO_WAIT = 3000

root = Tk()
root.geometry(f'100x100+{root.winfo_screenwidth()-100}+{root.winfo_screenheight()-100}')
root.after(TIME_TO_WAIT, root.destroy)
Message(title="Visual Studio Code", message="New Match Found", master=root).show()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文