from tkinter import *
from tkinter import scrolledtext
janela = Tk()
使两个小部件移动的功能
def scroll(*args):
eval("text_1.yview(*args)")
eval("text_2.yview(*args)")
此函数必须,当在两个文本小部件中的任何一个上单击鼠标滚轮时,两个小部件同时移动,就像在 scroll() 函数中一样
def move_scroll_and_texts():
pass
身体
frame = Frame(janela)
scroll_x = Scrollbar(janela, orient="horizontal")
text_1 = scrolledtext.ScrolledText(frame, wrap=NONE)
text_2 = Text(frame, wrap=NONE, width=5)
text_1.config(xscrollcommand=scroll_x.set)
scroll_x.configure(command=text_1.xview)
frame.pack()
text_2.pack(fill=X, side=LEFT)
text_1.pack(fill=X, side=LEFT)
scroll_x.pack(fill=X, side=BOTTOM)
当您滚动滚动条将触发绑定并将移动两个文本小部件
text_1.vbar.bind_all("<Configure>", lambda x: text_1.vbar.configure(command=scroll))
这个功能是我做不到的
text_1.bind("MouseWheel", lambda x: move_scroll_and_texts())
text_2.bind("MouseWheel", lambda x: move_scroll_and_texts())
for i in range(100):
text_1.insert(END, str(i)+"\n")
text_2.insert(END, str(i)+"\n")
janela.mainloop()