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

依然范特西╮ 提交于 2019-12-25 06:47:47

问题


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 visible. How can I do that ?


回答1:


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


来源:https://stackoverflow.com/questions/4531956/how-to-set-the-maximum-size-of-bwidgets-scrolledwindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!