2013-07-31 3 views
2

확인 여러 개의 탭 핸들, 나는이 간단한 코드가 있습니다파이썬 Tkinter를 :

import tkinter.filedialog 
from tkinter import * 
import tkinter.ttk as ttk 

root = Tk() 
root.title('test') 

nb = ttk.Notebook(root) 
nb.pack(fill='both', expand='yes') 

f1 = Text(root) 
f2 = Text(root) 
f3 = Text(root) 

nb.add(f1, text='page1') 
nb.add(f2, text='page2') 
nb.add(f3, text='page3') 

root.mainloop() 

을하고 난 그냥 궁금, Tkinter를 그들 텍스트와 함께 여러 탭을 처리하는 가장 좋은 방법은 무엇입니까? 마치 'page2'의 모든 텍스트를 지우거나 'page3'에 무언가를 삽입하고 싶다면 어떻게하면 좋을까요?

답변

2

당신은 이미 f1, f2f3의 텍스트 위젯에 대한 참조를 가지고, 그래서 당신은 직접 메서드를 호출 할 수 있습니다 :

f2.delete(1.0, 'end') # erase all the text on the 2nd tab 

f3.insert('end', 'hello, world') # insert text on the 3rd tab 

또한 경우, 목록에 위젯을 추가 할 수 있습니다 당신 모두에게 동일한 조치를 수행하려고합니다.

texts = [f1, f2, f3] 
for text in texts: 
    text.delete(1.0, 'end')