Skip to content Skip to sidebar Skip to footer

Tkinter Text Widget Setting Tabs

I have to set the tab size for my text widget to 4 characters. When I do textwidget.config(tabs = ('4c','8c')) I don't get the required results. It tabs by a lot which in now ways

Solution 1:

The documentation for the Tk text widget -tabs option mentions that a distance of 2c will be 2 centimeters. The documentation doesn't seem to say but this uses the Tk_GetPixels function to convert your option values into distances and here it states the following types:

<none> : The number specifies a distance in pixels.
c : The number specifies a distance in centimeters on the screen.
i : The number specifies a distance in inches on the screen.
m : The number specifies a distance in millimeters on the screen.
p : The number specifies a distance in printer's points (1/72 inch) on the screen.

If you want to use a distance in characters then you should use font measure using the font defined for your text widget and a suitable character like m or n given that for proportional fonts characters have different widths. An example of this is given in the Tk text widget -tabs documentation.

Post a Comment for "Tkinter Text Widget Setting Tabs"