Limiting scroll bar length
Asked Answered
C

1

6

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:

enter image description here

However I would like to make it look like what is seen in the "Notepad" application by Microsoft. This is how I want it:

enter image description here

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!

Circuity answered 24/1, 2014 at 9:28 Comment(1)
You know, if you accept an answer once in a while, it make people more motivated to answer other questions you may have.Onionskin
O
7

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).

Onionskin answered 24/1, 2014 at 10:57 Comment(1)
grid is indeed the way to solve this and the scrollbar problem is the original motivating use case; before it was invented, you had to do nasty tricks in pack with frames as spacers, and it was really quite hard to get right.Mikkimiko

© 2022 - 2024 — McMap. All rights reserved.