问题
At a Python 3.6.1 tkinter Text Widget with a lot of rows the added horizontal scrollbar varies length while the vertial one is scrolled (due to the different row lengths)
from tkinter import *
root = Tk()
menu = Menu(root)
root.config(menu=menu)
filemenu = Menu(menu)
menu.add_cascade(label="menu1", menu=filemenu)
filemenu.add_command(label="menu2")
text = Text(root, wrap=NONE)
scrollbarVertical = Scrollbar(root, orient=VERTICAL)
scrollbarHorizontal = Scrollbar(root, orient=HORIZONTAL)
scrollbarVertical.config(command=text.yview)
scrollbarHorizontal.config(command=text.xview)
scrollbarVertical.grid(row=0, column=1, sticky=NSEW)
scrollbarHorizontal.grid(row=1, column=0, sticky=NSEW)
text.config(yscrollcommand=scrollbarVertical.set)
text.config(xscrollcommand=scrollbarHorizontal.set)
text.grid(row=0, column=0, sticky=NSEW)
root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)
root.mainloop()
回答1:
There's nothing you can do about it -- the fundamental design of the horizontal scrollbar depends on the length of the longest visible line.
来源:https://stackoverflow.com/questions/46055885/python-3-6-1-tkinter-scrollbar-behavior