2011-08-06 59 views
1

私はそれぞれがスクロールバーを持つ2つのテキストボックスを取得しようとしています。しかし私はこれをしようとすると: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() 

この問題が発生した:場合

enter image description here

を、これは明らかではない、それらが機能的に内側のスクロールにバインドされた右のテキストボックスと2つの別々のテキストボックスです左のテキストボックスは機能的に外側のスクロールバーにバインドされています。

答えて

3

トリックは、フレームを使用し、ルートの代わりにフレームにスクロールバーを追加することです。

from Tkinter import * 

root = Tk() 

left = Frame(root) 
right = Frame(root) 

t_start = Text(left, width=20) 
t_start.pack(side=LEFT, fill=Y) 
s_start = Scrollbar(left) 
s_start.pack(side=RIGHT, fill=Y) 
s_start.config(command=t_start.yview) 
t_start.config(yscrollcommand=s_start.set) 

t_end = Text(right, width=20) 
t_end.pack(side=LEFT, fill=Y) 
s_end = Scrollbar(right) 
s_end.pack(side=RIGHT, fill=Y) 
s_end.config(command=t_end.yview) 
t_end.config(yscrollcommand=s_end.set) 

left.pack(side=LEFT, fill=Y) 
right.pack(side=RIGHT, fill=Y) 

root.geometry("500x200") 
root.mainloop() 

Two TkInter Text with Scrollbars

+0

パーフェクト。今、どのようにフレームに境界線と高さを付けますか? – JShoe

+0

梱包位置を修正しました。 – odie5533

+0

ありがとうございます、非アクティブな間もボックスに枠線を追加することは可能ですか? – JShoe

関連する問題