打开tkinter message框,该消息框在屏幕的右下角而不是中心
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:
But I would like it to open at the bottom right of the screen:
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):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面的代码在我的系统上工作,显示了显示屏右下角的消息框。 “窍门”是MessageBox在父窗口上摇摆,因此root.nemetry()的适当设置会导致它出现在将根窗口放在屏幕上的地方。您已经自己找到了它,但是root.withdraw()阻止了消息框的预期放置:
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: