tkMessageBox.showwarning如何选择弹出位置?

时间:2018-07-18 21:17:52

标签: python tkinter

我知道您可以使用几何来确定tkinter中窗口或顶层的位置,但是对于tkMessageBox呢?我有一个带有小型GUI的程序,它通常显示在屏幕的左上角,但弹出窗口始终显示在屏幕中间。我只需要一种在弹出窗口中使用几何图形(或类似图形)的方法。

非常感谢所有阅读的人!

1 个答案:

答案 0 :(得分:0)

上周我一直在调查,找到了解决方案, 它可以完美,轻松地包含在您的代码中。

在屏幕上居中根窗口

from tkinter import * 
root = Tk()


# Gets the requested values of the height and width.
windowWidth = root.winfo_reqwidth()
windowHeight = root.winfo_reqheight()

# Gets both half the screen width/height and window width/height
positionRight = int(root.winfo_screenwidth()/2 - windowWidth/2)
positionDown = int(root.winfo_screenheight()/2 - windowHeight/2)

# Positions the window in the center of the page.
root.geometry("+{}+{}".format(positionRight, positionDown))

我没有写这段代码,也记不住它的来源了,但还是要感谢作者。

相关问题