将 tkinter 窗口定位在屏幕边框处
我想在屏幕的右边框放置一个窗口。这是当前的代码,我认为这些常量应该是可以理解的。
root = Tk()
pos_x = root.winfo_screenwidth() - WINDOW_WIDTH
geometry = '{width}x{height}+{pos_x}+{pos_y}'.format(
height=WINDOW_HEIGHT, width=WINDOW_WIDTH, pos_y=HEIGHT_OFFSET, pos_x=pos_x)
root.wm_geometry(geometry)
问题是框架的宽度似乎是没有边框的可用空间,这意味着当我运行上面的代码时窗口不完全可见。我尝试了 root['border'] 但返回 0 并且谷歌对这个问题出奇的安静。
那么有没有办法获得框架的完整大小 - 或者这是使用 tkinter 执行此操作的错误方法?
I want to position a window at the right border of the screen. This is the current code, the constants should be comprehensible I think.
root = Tk()
pos_x = root.winfo_screenwidth() - WINDOW_WIDTH
geometry = '{width}x{height}+{pos_x}+{pos_y}'.format(
height=WINDOW_HEIGHT, width=WINDOW_WIDTH, pos_y=HEIGHT_OFFSET, pos_x=pos_x)
root.wm_geometry(geometry)
The problem is that the width of a frame seems to be the usable space without the border, which means that when I run the above code the window is not completely visible. I tried root['border'] but that returns 0 and google is surprisingly quiet about this problem.
So is there any way to get the complete size of a frame - or is this the wrong way to do this with tkinter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是窗口管理器绘制边框并没有告诉您它有多大。
您可以通过设置 overrideredirect 标志,但这意味着您不会得到窗口管理器绘制的边框。
但也许 Tcl'ers wiki 上的这个讨论会有所帮助,因为它讨论了查找完整窗口大小的方法。
The problem is that the window manager draws the border and does not tell you how large it is.
You can take full control of the window by setting the overrideredirect flag, but that would mean you do not get a border drawn by the window manager.
But maybe this discussion on the Tcl'ers wiki helps, as it discusses ways to find the full window size.