从右侧调整 Tkinter 窗口大小 (python)
我不确定如何表达这一点...
我有一个 Tkinter 窗口,当按下按钮时我需要隐藏该窗口的一半。 但是,我需要隐藏最左侧,以便窗口现在大小是原来的一半,
并显示原始窗口的右半部分。
Tkinter 的所有调整大小功能都从窗口的左侧开始。 更改几何值只能显示左侧,而隐藏右侧; 我需要逆数。
有人知道该怎么做吗?
(我不希望用户必须拖动窗口边框, 我需要按钮来自动化它)。
规格:
- Python 2.7.1
- Tkinter
- Windows 7
I'm not sure on how to articulate this...
I have a Tkinter window, and I need to hide half of this window when a button is pressed.
However, I need the left-most side to be hidden, so that the window is now half the size it originally was,
and shows the right half of the original window.
All of Tkinter's resize functions span from the left side of the window.
Changing the geometry values can only show the left side whilst hiding the right;
I need the inverse.
Does anybody know how to go about doing this?
(I don't want the user to have to drag the window border,
I need the button to automate it).
Specs:
- Python 2.7.1
- Tkinter
- Windows 7
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是你想要的吗?
does this do what you want ?
您可以通过在正确的位置使用减号来使用右锚定几何规范:
但是,我不知道这是否适用于Windows(上面是X11技巧,我不知道它是否在Windows中实现)平台兼容层与否);您可能只需根据左侧的投影尺寸计算新位置并使用它。
You can use right-anchored geometry specifications by using a minus sign in the right place:
However, I don't know if this will work on Windows (the above is an X11 trick, and I don't know if it is implemented in the platform-compatibility layer or not); you might have to just calculate the new position given the projected size of the left side and use that.
我的 IT 老师有一个建议:
添加一个看不见的滚动条,
调整根窗口大小后,
强制滚动条一直滚动到右侧。
(所以我想我必须创建一个画布,
将我所有的小部件打包到框架中,
将框架包装到画布上,
使用滚动条配置画布?)
我不确定是否有一个函数可以设置滚动条的当前位置(即窗口的 xview),
但我想是有的。
尚未实施,但看起来很有希望。
感谢您的建议!
My IT teacher had a suggestion:
Add a Scrollbar out of sight,
and after resizing the root window,
force the scrollbar to scroll all the way to the right.
(So I guess I'd have to create a canvas,
pack all my widgets to the frame,
pack the frame to the canvas,
configure the canvas with the scrollbar?)
I'm not sure if there's a function to set the current position of the scrollbar (thus xview of the window),
but I'd imagine there is.
Have yet to implement this, but it looks promising.
Thanks for the suggestions!