如何设置BWidget的ScrolledWindow的最大大小? [英] How to set the maximum size of BWidget's ScrolledWindow?

查看:78
本文介绍了如何设置BWidget的ScrolledWindow的最大大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在像这样的代码中使用BWidgetScrolledWindow:

I am using BWidget's ScrolledWindow in a code like this:

toplevel .top
set w [ScrolledWindow .top.scrolledWindow]
set f [ScrollableFrame $w.scrollableFrame -constrainedwidth true]
$w setwidget $f
set a [$f getframe]
# here goes some stuff in $a

所以我得到一个带有垂直滚动条的窗口.当增加.top的高度时,过一会儿$a中的所有内容变为可见,并且滚动条消失,因为不再需要它.如何禁止进一步增加.top的高度?也就是说,当$ a的所有内容都可见时,我需要将.top的最大高度设置为该值.我该怎么办?

So I get a window with vertical scrollbar. When increasing the height of .top, after some moment all the content in $a becomes visible and the scrollbar disappears as it is not needed anymore. How can I forbid further increasing the height of .top? i.e. I need to set the maximum height of .top to the value when all content of $a is visible. How can I do that ?

推荐答案

要设置顶层的最大高度,请使用 winfo height (在另一个维度中为winfo width).结合这些:

To set the maximum height of a toplevel, you use wm maxsize, possibly with a very large value for the horizontal size. To get the current size of it, you use winfo height (and winfo width in the other dimension). Combining these:

# 10k is just a "big" number
wm maxsize .top 10000 [winfo height .top]

现在,BWidget的棘手之处在于它不会立即设置窗口大小,甚至不会在第一次显示时设置窗口大小.这意味着您必须猜测何时配置窗口.可以尝试的便宜方法是将其放置在将来的半秒内.毕竟,即使是专业用户,也有可能在与之交互之前至少花费一点时间.可以通过 after 来完成:

Now, the tricky bit with BWidget is that it doesn't set the size of the window immediately, or even on first display. This means that you have to put in a guess about when to configure the window. A cheap thing to try is to put it half a second in the future; after all, even expert users are likely to spend at least a little while looking before interacting with it. That's done with after like this:

# 500 milliseconds in the future
after 500 {
    # 10k is just a "big" number
    wm maxsize .top 10000 [winfo height .top]
}

这篇关于如何设置BWidget的ScrolledWindow的最大大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆