I am new to Tkinter GUI, and trying to achieve following
I've dataframe df
AccountName Group1 Group2 Group3
Cost Global Global Global
Cost Global Global Global
Cost Global Global Global
Cost Region Total Asia Asia
Cost Region Asia Singapore
Cost Region Asia Indonesia
I've Three list boxes in TK frame with unique values and an additional text items "Select ALL" in each list boxes
Group1 Group2 Group3
Global Global Global
Region Total Asia Asia
Select All Asia Singapore
Select All Indonesia
Select All
I want to bind these list boxes together in a way that if I select a value in Group1 then only related values should appear in Group2 and Group3. Similarly, if I select a value in Group2 then only related value should appear in Group3. In addition, if I select 'Select ALL' then other list boxes should show all values.
Expected Output
Example1: If Group1 selection is Region
Group1 Group2 Group3
Region Total Asia Asia
Asia Singapore
Select ALL Indonesia
Select ALL
Example2: If Group1 selection is Select ALL
Group1 Group2 Group3
Select ALL Global Global
Total Asia Asia
Asia Singapore
Select ALL Indonesia
Select ALL
Example 3: If Group1 Selection is Region and Group2 Selection is Asia
Group1 Group2 Group3
Region Asia Singapore
Indonesia
Select ALL
Coding I've done coding to assign values to list box through dataframe but not sure how to proceed further
import tkinter as tk
import pandas as pd
import DataImport as dI
df = dI.import_Data()
def listing(data):
a = []
for i in data:
if i not in a:
a.append(i)
return a
G1 = listing(df["Groupby_L1"].tolist())
G1.append(" Select ALL")
G2 = listing(df["Groupby_L2"].tolist())
G2.append("Select ALL")
G3 = listing(df["Groupby_L3"].tolist())
G3.append("Select ALL")
def listboxs(listbox, data):
i = 0
for widget in data:
listbox.insert(i, widget)
i = i + 1
#in tk frame I am using follwing code
Group1 = Label(frame1)
Group1.config(text='Groupby_L1')
Group1.grid(column='1', ipadx='10', padx='5', pady='30', row='1')
Group1_Data = Listbox(frame1, selectmode=MULTIPLE)
Group1_Data.config(height=3, width=20)
listboxs(Group1_Data, G1)
Group1_Data.grid(column='2', row='1')
Group2 = Label(frame1)
Group2.config(text='Groupby_L2')
Group2.grid(column='15', padx='60', row='0')
Group2_Data = Listbox(frame1, selectmode=MULTIPLE)
Group2_Data.config(height=3, width=20)
listboxs(Group2_Data, G2)
Group2_Data.grid(column='20', row='0')
Group3 = Label(frame1)
Group3.config(text='Groupby_L3')
Group3.grid(column='15', padx='60', row='1')
Group3_Data = Listbox(frame1, selectmode=MULTIPLE)
Group3_Data.config(height=3, width=20)
listboxs(Group3_Data, G3)
Group3_Data.grid(column='20', row='1')