Python 3.6.1 tkinter Scrollbar behavior

雨燕双飞 提交于 2020-01-14 03:13:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!