限制滚动条长度 [英] Limiting scroll bar length
问题描述
我正在尝试使用Perl Tk创建一个简单的记事本,例如GUI.我已经使用 Scrolled 小部件创建了具有两个滚动条的 Text 小部件-一个在右侧,一个在底部.两个滚动条相遇的地方如下所示:
但是,我想使它看起来像Microsoft在记事本"应用程序中看到的一样.这就是我想要的:
如您所见,现在有一个空方格",两个滚动条在此相交.记事本的另一个功能是可以使用此正方形"来调整窗口大小.我希望能够达到同样的效果.
我该怎么做?
谢谢!
诀窍是使用grid
几何管理器放置小部件,该管理器实际上会创建一个(大小不均的)4x4网格,其中文本小部件位于北部". -West",垂直滚动条在"North-East",水平滚动条在"South-West",空方格在"South-East". 手册页上有一个相关示例.
我认为我可以引用手册页示例作为合理使用(请注意,其版权©1995-1997 Roger E. Critchlow Jr.版权所有©1996 Sun Microsystems,Inc.).
# Make the widgets
toplevel .t
text .t.txt -wrap none -xscroll {.t.h set} -yscroll {.t.v set}
scrollbar .t.v -orient vertical -command {.t.txt yview}
scrollbar .t.h -orient horizontal -command {.t.txt xview}
# Lay them out
grid .t.txt .t.v -sticky nsew
grid .t.h -sticky nsew
# Tell the text widget to take all the extra room
grid rowconfigure .t .t.txt -weight 1
grid columnconfigure .t .t.txt -weight 1
但是,您将自己翻译成Perl-Tk.在TkDocs的此处中,有一些与Perl-Tk有关的网格讨论(尽管不是专门关于滚动条的).你开始了. "Learning Perl/Tk"示例章节几何管理还讨论了grid
.
哦!您还希望在第四个方框中调整大小.在Tcl/T(t)k中,它称为ttk::sizegrip
,并在此处中进行了记录.我从来没有亲自使用过它(因为还有其他方法可以调整窗口的大小),也不知道它是否在Perl-Tk中.如果不是,那么会有一个 wiki页面讨论如何伪造它(同样,我从未亲自尝试过该代码)./p>
I am trying to create a simple notepad like GUI using Perl Tk. I have used the Scrolled widget to create a Text widget with two scrollbars - one on the right and one on the bottom. The place where the two scrollbars meet looks like this:
However I would like to make it look like what is seen in the "Notepad" application by Microsoft. This is how I want it:
As you can see, there is a now an "empty square" where the two scrollbars meet. One more feature of notepad is that this "square" can be used to resize the window size. I want to be able to achieve the same.
How do I go about doing this?
Thanks!
The trick is to place the widgets with the grid
geometry manager, which essentially creates an (uneven-sized) 4x4 grid with the text widget at "North-West", the vertical scrollbar at "North-East", the horizontal scrollbar at "South-West", and the empty square at "South-East". There is a relevant example on the man page.
I think I'm allowed to quote the man page example as fair use (noting that it's Copyright © 1995-1997 Roger E. Critchlow Jr. Copyright © 1996 Sun Microsystems, Inc.).
# Make the widgets
toplevel .t
text .t.txt -wrap none -xscroll {.t.h set} -yscroll {.t.v set}
scrollbar .t.v -orient vertical -command {.t.txt yview}
scrollbar .t.h -orient horizontal -command {.t.txt xview}
# Lay them out
grid .t.txt .t.v -sticky nsew
grid .t.h -sticky nsew
# Tell the text widget to take all the extra room
grid rowconfigure .t .t.txt -weight 1
grid columnconfigure .t .t.txt -weight 1
You'll have translate to Perl-Tk yourself, however. There is some Perl-Tk-related discussion of grid (though not specifically about scrollbars) here at TkDocs that might get you started. The "Learning Perl/Tk" sample chapter Geometry Management also discusses grid
.
Oh! You wanted a resizing control in the fourth square as well. In Tcl/T(t)k, it's called a ttk::sizegrip
and it's documented here. I've never used it myself (as there are other ways to resize the window) and don't know if it's in Perl-Tk. If it's not, there is a wiki page discussing how to fake it (again, I've never tried that code myself).
这篇关于限制滚动条长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!