Python 3.6.1 tkinter滚动条行为 [英] Python 3.6.1 tkinter Scrollbar behavior

查看:102
本文介绍了Python 3.6.1 tkinter滚动条行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在具有很多行的Python 3.6.1 tkinter文本小部件上,添加的水平滚动条在滚动垂直行时会改变长度(由于行长不同)

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

推荐答案

您无能为力-水平滚动条的基本设计取决于最长的 visible 行的长度.

There's nothing you can do about it -- the fundamental design of the horizontal scrollbar depends on the length of the longest visible line.

这篇关于Python 3.6.1 tkinter滚动条行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆