python - tkMessageBox.showwarning 如何选择弹出位置?
问题描述
我知道您可以使用几何来确定 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))
这段代码不是我写的,也不记得是从哪里来的,不过还是感谢作者。
推荐阅读
- android - 在 Firebase 文档中的列表开头插入新的孩子
- excel - VB.Net COMException 尝试将数据从一个 Excel 文档粘贴到另一个
- flutter - 如何减少 Flutter Web 应用程序的加载时间
- php - 如何在 woocommerce 计费字段之间插入元素?
- selenium-webdriver - 范围报告版本 4 - 为所有已执行的测试用例创建两个范围报告而不是一个 html 报告
- python - 为什么这条sql语句超级慢?
- javascript - 获取并写入 js 文件中的 json 文档
- flutter - 如何设置 Flutter showMenu 起点
- matlab - 我试图使用 LSB 将图像隐藏在另一个图像中,但生成的图像以高对比度出现
- c++ - 无法打印正确的结果