从右侧调整 Tkinter 窗口大小 (python)

发布于 2024-11-27 01:54:00 字数 326 浏览 1 评论 0原文

我不确定如何表达这一点...

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

横笛休吹塞上声 2024-12-04 01:54:01

这是你想要的吗?

import Tkinter as Tk #tkinter

def toggle():
    if frame1.winfo_ismapped():
        frame1.grid_remove()
    else:
        frame1.grid()

root = Tk.Tk()
root.geometry('-450+250')
frame1 = Tk.Frame(root, width=200, height=100, bg='red')
frame1.grid(row=0, column=0)
frame2 = Tk.Frame(root, width=200, height=100, bg='blue')
frame2.grid(row=0, column=1)
Tk.Button(root, text='toggle', command=toggle).grid(row=1, column=1)

root.mainloop()

does this do what you want ?

import Tkinter as Tk #tkinter

def toggle():
    if frame1.winfo_ismapped():
        frame1.grid_remove()
    else:
        frame1.grid()

root = Tk.Tk()
root.geometry('-450+250')
frame1 = Tk.Frame(root, width=200, height=100, bg='red')
frame1.grid(row=0, column=0)
frame2 = Tk.Frame(root, width=200, height=100, bg='blue')
frame2.grid(row=0, column=1)
Tk.Button(root, text='toggle', command=toggle).grid(row=1, column=1)

root.mainloop()
月棠 2024-12-04 01:54:01

您可以通过在正确的位置使用减号来使用右锚定几何规范:

123x467-78+9

但是,我不知道这是否适用于Windows(上面是X11技巧,我不知道它是否在Windows中实现)平台兼容层与否);您可能只需根据左侧的投影尺寸计算新位置并使用它。

You can use right-anchored geometry specifications by using a minus sign in the right place:

123x467-78+9

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.

另类 2024-12-04 01:54:01

我的 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文