0

I want my second frame to be updated with by the drop down value I choose. Literally my values on my dropdown are dictionaries. What I want all values of each key to go into the their respective places in the second frame.

Here is my code:

from tkinter import *
from tkinter import  ttk # necessary for Notebook
from tkinter import filedialog
import pandas as pd
import numpy as np

######################## GUI SETUP ###################

root =Tk()
root.title('My GUI')
root.geometry('800x600')

# Instantiating the notebook

nbook=ttk.Notebook(root)
nbook.pack(pady='25')


frame_1=Frame(nbook, width=800, height=600, bg='grey')
frame_2=Frame(nbook, width=800, height=600, bg='white')

# Frame packing
frame_1.pack(fill='both', expand=1)
frame_2.pack(fill='both', expand=1)

# Find a way to pack themall together elegeantly
nbook.add(frame_1, text="Setup")
nbook.add(frame_2, text="Overview")

### Dropdown #####
lista=['Pod1','Pod2','Pod3','Pod4']

click=StringVar()
click.set('Select Options')

options=OptionMenu(frame_1, click, *lista)
options.pack()

#### Overview tab ######
Label_1=Label(frame_2, text='Main')
Label_1.place(x=70, y=30)

Label_2=Label(frame_2, text='Second')
Label_2.place(x=350, y=30)

Label_3=Label(frame_2, text='Others')
Label_3.place(x=600,y=30)

pod1={'Main':['Strawberries','Blueberries','Raspberries'],'Second':    ['Blackberries', 'Burberries'], 'Rest':None}
pod2={'Main':['Mangoes', 'Guavas'],'Second':['Coconut'],'Rest': None}
pod3={'Main':['Tiger', 'Lions'],'Second':['Leopard','Cheetah'], ,'Rest': ['Cat', 'Lynx','C']}

root.mainloop() # this must end the program
xray84
  • 7
  • 3

1 Answers1

0

Does this give you somewhat of an idea of how to proceed, i just did it really quick and it should give you some idea :D

Change your dictionary to :

pod1={'Main':['Strawberries','Blueberries','Raspberries'],'Second':['Blackberries', 'Burberries'], 'Rest':['None']}
pod2={'Main':['Mangoes', 'Guavas'],'Second':['Coconut'],'Rest': ['None']}
pod3={'Main':['Tiger', 'Lions'],'Second':['Leopard','Cheetah'], 'Rest': ['Cat', 'Lynx','C']}

Make a button and function it like

b = Button(frame_1,text='Click me!',command=hmm)
b.pack(pady=20)

Define the function

def hmm():
    global la
    if click.get() == 'Pod1':
        for index,l in enumerate(pod1['Main']):
            la = Label(frame_2,text='')
            la.place(x=70,y=index*25+50)
            la.config(text=l)
        for index1,l1 in enumerate(pod1['Second']):
            la = Label(frame_2,text='')
            la.place(x=350,y=index1*25+50)
            la.config(text=l1)
        for index2,l2 in enumerate(pod1['Rest']):
            la = Label(frame_2,text='')
            la.place(x=600,y=index2*25+50)
            la.config(text=l2)

    elif click.get() == 'Pod2':
        for index,l in enumerate(pod2['Main']):
            la = Label(frame_2,text='')
            la.place(x=70,y=index*25+50)
            la.config(text=l)
        for index1,l1 in enumerate(pod2['Second']):
            la = Label(frame_2,text='')
            la.place(x=350,y=index1*25+50)
            la.config(text=l1)
        for index2,l2 in enumerate(pod2['Rest']):
            la = Label(frame_2,text='')
            la.place(x=600,y=index2*25+50)
            la.config(text=l2)
    
    elif click.get() == 'Pod3':
        for index,l in enumerate(pod3['Main']):
            la = Label(frame_2,text='')
            la.place(x=70,y=index*25+50)
            la.config(text=l)
        for index1,l1 in enumerate(pod3['Second']):
            la = Label(frame_2,text='')
            la.place(x=350,y=index1*25+50)
            la.config(text=l1)
        for index2,l2 in enumerate(pod3['Rest']):
            la = Label(frame_2,text='')
            la.place(x=600,y=index2*25+50)
            la.config(text=l2)

Let me know if anything is unclear and this is just the idea of how I thought of it, you can totally proceed in a different way and might get a better output too. Cheers

Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
  • It has its own downside, like if you choose something like pod2, it will then overwrite the labels, mayb post this new error as a new Q, someone will definitely help you out – Delrius Euphoria Jul 28 '20 at 05:36