Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tab position in TEXT Widget

Status
Not open for further replies.

akpr

Programmer
Jul 25, 2001
19
US
How do I set user defined tab position in TEXT Widget
i.e.
I have a variable, depends upon that variable tab position should be set.
i.e. if user set 4. Tab position should 4
 
The Text widget has a -tabs attribute that allows you to set default tabs stops. Simply provide a list of tab stops, using any valid Tk screen distances. (A number by itself is interpreted as pixels. The suffix "i" indicates inches, "c" indicates centimeters, "m" millimeters, and "p" typographical points.) For example:

Code:
text .t -tabs {0.5i 1.25i}
pack .t
.t insert end "1:\tCA\tSan Francisco\n"
.t insert end "2:\tOR\tPortland\n"

The Text widget support several types of alignments. Quoting from the Text widget manual page:

Each position may optionally be followed in the next list element by one of the keywords left, right, center, or numeric, which specifies how to justify text relative to the tab stop. Left is the default; it causes the text following the tab character to be positioned with its left edge at the tab position. Right means that the right edge of the text following the tab character is positioned at the tab position, and center means that the text is centered at the tab position. Numeric means that the decimal point in the text is positioned at the tab position; if there is no decimal point then the least significant digit of the number is positioned just to the left of the tab position; if there is no number in the text then the text is right-justified at the tab position. For example:

Code:
.t configure -tabs {2c left 4c 6c center}

creates three tab stops at two-centimeter intervals; the first two use left justification and the third uses center justification.

You can also specify the tab stops on a line-by-line basis. To do so, create a tag and configure the tab stops for that tag. Then apply the tag to the line of text that you want to use those tab stops. For example:

Code:
.t tag configure three-column -tabs {1i 2i}
.t tag configure four-column -tabs {0.75i 1.5i 2.25i}
.t insert end "One\tTwo\tThree\n" three-column
.t insert end "One\tTwo\tThree\tFour\n" four-column
- Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top