python tkinter滚动条和文本小部件问题
我正在尝试获取两个都有滚动条的文本框。但是,当我尝试此操作时:
from Tkinter import *
root = Tk()
s_start = Scrollbar(root)
t_start = Text(root, width=50, height=10)
t_start.focus_set()
s_start.pack(side=RIGHT, fill=Y)
t_start.pack(side=LEFT, fill=Y)
s_start.config(command=t_start.yview)
t_start.config(yscrollcommand=s_start.set)
s_end = Scrollbar(root)
t_end = Text(root, width=50, height=10)
t_end.focus_set()
s_end.pack(side=RIGHT, fill=Y)
t_end.pack(side=LEFT, fill=Y)
s_end.config(command=t_end.yview)
t_end.config(yscrollcommand=s_end.set)
root.mainloop()
会发生这种情况:
如果不清楚,这些是两个单独的文本框,右侧文本框在功能上绑定到内部滚动条,左侧文本框在功能上绑定到外部滚动条。
I'm trying to get two text boxes that each have scrollbars. When I try this however:
from Tkinter import *
root = Tk()
s_start = Scrollbar(root)
t_start = Text(root, width=50, height=10)
t_start.focus_set()
s_start.pack(side=RIGHT, fill=Y)
t_start.pack(side=LEFT, fill=Y)
s_start.config(command=t_start.yview)
t_start.config(yscrollcommand=s_start.set)
s_end = Scrollbar(root)
t_end = Text(root, width=50, height=10)
t_end.focus_set()
s_end.pack(side=RIGHT, fill=Y)
t_end.pack(side=LEFT, fill=Y)
s_end.config(command=t_end.yview)
t_end.config(yscrollcommand=s_end.set)
root.mainloop()
This happens:
In case this isn't clear, those are two separate text boxes, with the right textbox functionally bound to the inner scroll bar, and the left textbox functionally bound to the outer scrollbar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
诀窍是使用框架并将滚动条添加到框架而不是根。
The trick is to use Frames and add the Scrollbars to the Frames instead of to Root.