Tkinter Text widget scroll bar doesn't show the first character

Question:

I am trying to make a horizontal scroll bar for a text widget in tkinter, it works but when the text is long, it starts not showing some parts of the first character untill it’s totally disappeared.

You can see some pixels of the first character in this image

That’s my code:

scrollbar = Scrollbar(window, orient='horizontal')
scrollbar.pack(side=BOTTOM, fill=X)

text = Text(window, font=("Calibri", 40), xscrollcommand=scrollbar.set)
text.tag_configure("center", justify='center')
text.insert("1.0", "222222222222222222222222222222")
text.tag_add("center", "1.0", "end")
text.config(width=100, height=1, background="#f2f2f2", borderwidth=0, state='disabled', wrap='none')
text.pack(pady=24)
scrollbar.config(command=text.xview)

Answers:

I changed root.resizable(280, 20), try this:

from tkinter import*

root = Tk()
root.resizable(280, 20)
root.title("Scrollbar Widget Example")

scrollbar = Scrollbar(root, orient='horizontal')
scrollbar.pack(side=BOTTOM, fill=X)

text = Text(root, font=("Calibri", 40), xscrollcommand=scrollbar.set)
text.tag_configure("center", justify='center')
text.insert("1.0", "222222222222222222222222222222")
text.tag_add("center", "1.0", "end")
text.config(width=30, height=1, background="#f2f2f2", borderwidth=0, state='disabled', wrap='none')
scrollbar.config(command=text.xview)
text.pack(pady=24)
 
root.mainloop()
Answered By: toyota Supra
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.