Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python tkMessageBox.showwarning如何选择弹出窗口的位置?_Python_Tkinter - Fatal编程技术网

Python tkMessageBox.showwarning如何选择弹出窗口的位置?

Python tkMessageBox.showwarning如何选择弹出窗口的位置?,python,tkinter,Python,Tkinter,我知道你可以用几何学来确定tkinter中窗口或顶层的位置,但是tkMessageBox呢?我有一个带有小型GUI的程序,它通常出现在屏幕的左上角,但弹出窗口总是指向屏幕的中间。我只需要在弹出窗口中使用几何体(或类似的东西)的方法 非常感谢所有的读者 我上周研究了这个问题,找到了这个解决方案, 它可以完美地工作,并且很容易包含在代码中 在屏幕上对中根窗口 from tkinter import * root = Tk() # Gets the requested values of the

我知道你可以用几何学来确定tkinter中窗口或顶层的位置,但是tkMessageBox呢?我有一个带有小型GUI的程序,它通常出现在屏幕的左上角,但弹出窗口总是指向屏幕的中间。我只需要在弹出窗口中使用几何体(或类似的东西)的方法


非常感谢所有的读者

我上周研究了这个问题,找到了这个解决方案, 它可以完美地工作,并且很容易包含在代码中

在屏幕上对中根窗口

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

我没有写这段代码,也记不起它是从哪里来的,不过还是要感谢作者。

对不起,不可能。Tkinter只是将您的请求传递给操作系统,操作系统决定窗口的位置。我在Linux上测试过,弹出窗口总是以GUI为中心;在Windows上,弹出窗口总是集中在显示器上。如果它真的很重要,你可以轻松地创建自己的弹出窗口。