user interface - Python tkinter: Handle multiple tabs -
ok, have simple code:
import tkinter.filedialog tkinter import * import tkinter.ttk 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()
and wondering, best way handle multiple tabs text on them in tkinter? if wanted erase text on 'page2' or insert on 'page3' how that?
you have references text widgets in f1
, f2
, f3
, can call methods directly:
f2.delete(1.0, 'end') # erase text on 2nd tab f3.insert('end', 'hello, world') # insert text on 3rd tab
you might want add widgets list, in case want perform same action all.
texts = [f1, f2, f3] text in texts: text.delete(1.0, 'end')
Comments
Post a Comment