简体   繁体   中英

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

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)

I change 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM