Tk - Scrollbar Widget


Advertisements

Scrollbar widget is a scrolling widget that can work without a text or canvas widgets. The syntax for scrollbar widget is shown below.

scrollbar scrollbarName options

Options

The options available for the scrollbar widget are listed below in table.

Sr.No. Syntax & Description
1

-background color

Used to set background color for widget.

2

-borderwidth width

Used to draw with border in 3D effects.

3

-orien orientation

Sets the orientation for widget. It can be either horizontal or vertical.

4

-relief condition

Sets the 3D relief for this widget. The condition may be raised, sunken, flat, ridge, solid, or groove.

5

-command command

Command links view to scrollbar widget.

A simple example for scrollbar widget is shown below −

#!/usr/bin/wish

grid [tk::listbox .l -yscrollcommand ".s1 set" -xscrollcommand ".s2 set" -height 5 -width
   20] -column 0 -row 0 -sticky nwes
grid [ttk::scrollbar .s1 -command ".l yview" -orient vertical -background yellow
   -borderwidth 5 -relief ridge] -column 1 -row 0 -sticky ns
grid [ttk::scrollbar .s2 -command ".l xview" -orient horizontal -background yellow
   -borderwidth 5 -relief ridge] -column 0 -row 1 -sticky ew

for {set index 0} {$index<100} {incr index} {
   .l insert end "A long line of text for testing scrollbar."
}

When we run the above program, we will get the following output −

Scrollbar Widget
tk_mega_widgets.htm
Advertisements