Search code examples
tkinterscrollbar

tkinter: my scrollbar hides some characters


I have a the main window in my program as a Text widget, with a vertical scrollbar on the right side, along all its height - with the usual code:

yscrollbar=Scrollbar(mytext, orient=VERTICAL, command=mytext.yview)
mytext["yscrollcommand"]=yscrollbar.set

It is just annoying that when I insert/input text, the last 1-2 characters before the line returns are hidden by the scrollbar.

There is some easy way to tell the text widget to return the line before hitting the scrollbar?

PS the main window is user resizable, so I'm looking for some general solution...


Solution

  • Based on your response to a question, the problem is that you are placing the scrollbar inside the text widget rather than alongside it. The solution is to give both the text widget and the scrollbar the same parent.

    If you want the visual effect of the scrollbar being in the text widget, create a frame and give it a borderwidth of 1 and a relief of "sunken". Then, give your text widget a borderwidth of zero. Place both the text widget and the scrollbar in this frame and the scrollbar will have the appearance of being inside the text widget.