Quantcast
Channel: Active questions tagged tabs - Stack Overflow
Viewing all articles
Browse latest Browse all 587

How to save the contents of dynamic tabs in a GUI with tkinter

$
0
0

I'm having trouble saving the contents of dynamic tabs in a GUI environment made with tkinter in Python. When I enter the contents and click the save button, the text file created only says , Tab0: Content for Tab 1, etc. Here is the script I'm working with.

import tkinter as tkfrom tkinter import ttkfrom tkinter import filedialogvariables = dict()def add_vehicle_tab():    v_info = ttk.Frame(tab_control)    tab_control.add(v_info, text='Tab {}'.format(tab_control.index(tk.END)))    #add content here    variables['VEH_MAKE'] = tk.StringVar(value='')    ttk.Label(v_info, text= 'VEH_MAKE').grid(row=2, column=0)    ttk.Entry(v_info, textvariable=variables['VEH_MAKE']).grid(row=3, column=0,sticky=(tk.W+tk.E))    variables['COLOR'] = tk.StringVar(value='')    ttk.Label(v_info, text= 'COLOR').grid(row=4, column=0)    ttk.Entry(v_info, textvariable=variables['COLOR']).grid(row=5, column=0,sticky=(tk.W+tk.E))        variables['YEAR'] = tk.IntVar(value='')    ttk.Label(v_info, text= 'YEAR').grid(row=6, column=0)    ttk.Entry(v_info, textvariable=variables['YEAR']).grid(row=7, column=0,sticky=(tk.W+tk.E))    tab_content[tab_control.index(v_info)] = "Content for Tab{}".format(tab_control.index(tk.END))def save_tabs():    folder_path = filedialog.askdirectory()    if folder_path:        file_path: "C:/" +"/tabs_data.txt"        with open("C:/tabs_data.txt", "w") as file:            for index, content in tab_content.items():                file.write("Tab {}:\n".format(index, content))root = tk.Tk()root.title('Vehicle tabs')tab_control = ttk.Notebook(root)tab_control.pack(expand=1, fill='both')tab_content = {}add_tab_button = tk.Button(root, text='Add vehicle tab', command=add_vehicle_tab)add_tab_button.pack()save_button = tk.Button(root, text="Save Tabs", command=save_tabs)save_button.pack()root.mainloop()

I'm not sure why the contents of the tabs (VEH_MAKE, COLOR, YEAR) are not being saved. What am I missing here?


Viewing all articles
Browse latest Browse all 587

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>