问题
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!
回答1:
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).
来源:https://stackoverflow.com/questions/21328952/limiting-scroll-bar-length