Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limiting scroll bar length

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!

like image 505
Liam Willis Avatar asked Jan 24 '14 09:01

Liam Willis


People also ask

How do I shorten a scroll bar?

Resize the Horizontal Scroll BarPlace the mouse pointer over the vertical ellipsis (three vertical dots) next to the horizontal scroll bar. The mouse pointer changes to a double-headed arrow. Drag to the right to shrink the horizontal scroll bar or drag to the left to enlarge the scroll bar.

How do I get rid of the extra scroll bar in Excel?

Click the File tab. Click Options, and then click the Advanced category. Under Display options for this workbook, clear or select the Show horizontal scroll bar check box and Show vertical scroll bar check box to hide or display the scroll bars.

How do I reduce the size of the scrollbar in HTML?

scrollbar-width accepts the following values: auto is the default value and will render the standard scrollbars for the user agent. thin will tell the user agent to use thinner scrollbars, when applicable. none will hide the scrollbar completely, without affecting the element's scrollability.


1 Answers

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

like image 198
Peter Lewerin Avatar answered Sep 28 '22 06:09

Peter Lewerin