Skip to content

Instantly share code, notes, and snippets.

@israel-dryer
Created April 22, 2021 13:01
Show Gist options
  • Save israel-dryer/b60be5d7b2756b180d8b3377620d332e to your computer and use it in GitHub Desktop.
Save israel-dryer/b60be5d7b2756b180d8b3377620d332e to your computer and use it in GitHub Desktop.
example of saving text from one tab onto another in tkinter
import tkinter as tk
from tkinter import ttk
def submit(source, dest):
"""Collect data from source text and insert into destination text"""
text = source.get('1.0', 'end')
dest.insert('end', text)
root = tk.Tk()
nb = ttk.Notebook(root)
nb.pack(fill='both', expand='yes')
# page 1 setup
page1 = ttk.Frame(nb)
text1 = tk.Text(page1)
text1.pack(fill='both', expand='yes')
b1 = ttk.Button(page1, text='Submit to Page 2')
b1.pack(fill='x')
nb.add(page1, text='Page 1')
# page 2 setup
page2 = ttk.Frame(nb)
text2 = tk.Text(page2)
text2.pack(fill='both', expand='yes')
nb.add(page2, text='Page 2')
# configure button callback
b1.configure(command=lambda x=text1, y=text2: submit(x, y))
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment