0

My intention is to add a vertical bar to IDLE to indicate preferred line length at column 80.

I have tried to find a configuration option for the Text tkinter widget that would allow this but have found nothing.

I was hoping it would be a simple configuration option so I could just add a another item the text_options dictionary within EditorWindow.py found within Python\Lib\idlelib.

I am not sure how styles/themes work but do they have the capability to change the background colour of only 1 column in a Text widget?

1 Answers1

0

Outline of possible solution:

  • Create a 1-pixel wide Frame, with a contrasting background color, as a child of the Text.
  • Use .place() to position the Frame at an appropriate horizontal coordinate.

Possible issues:

  • I don't see any easy way to get the coordinate for a particular column. Text.bbox("1.80") looks promising, but doesn't work unless there actually are 80 characters in the line already. You may have to insert a dummy 80-character line at first, call update_idletasks to get the Text to calculate positions, call bbox to get the coordinates, then delete the dummy text. Repeat whenever the display font is changed.
  • The line would necessarily appear on top of any text or selection region, which isn't quite the visual appearance I'd expect for a feature like this.
jasonharper
  • 9,450
  • 2
  • 18
  • 42