开发者

How to set the maximum size of BWidget's ScrolledWindow?

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

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 vi开发者_运维问答sible. How can I do that ?


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]

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]
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜