Click here to Skip to main content
14,972,394 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey, In my tkinter program i want to create a combobox and based on 1st combobox input 2nd combo box value will display. I think to do this I need to in reload combobox I don't have any idea how to do that. Can you please help me

Below my code

What I have tried:

import tkinter
import os
from tkinter import ttk
from tkinter import *
from data.binding import *
frame3=Tk()


Label(frame3,text="Shop Name").place(x=100,y=50)
shop_name=[]
pn=[]
addd=[]
myVar=StringVar()
if os.path.isfile("C:\\Dragon\dealer.txt"):
    with open ("C:\\Dragon\dealer.txt") as sn:
        for line in sn:
            if line.split(";")[0] not in shop_name:
                shop_name.append(line.split(';')[0].strip())
shopauto=ttk.Combobox(frame3,values=shop_name,width=30)
shopauto.bind("<<ComboboxSelected>>",select(pn,addd,myVar))
shopauto.place(x=230,y=50)
Label(frame3,text="Proprietor Name").place(x=100,y=90)
proname=ttk.Combobox(frame3,values=pn)
proname.place(x=230,y=90)

frame3.mainloop()


#############################################
import os
def select(pn,addd,myVar):
    if os.path.isfile("C:\\Dragon\dealer.txt"):
        with open("C:\\Dragon\dealer.txt") as p:
            for line in p:
                if myVar.get() == line.split(';')[0].strip():
                    pn.append(line.split(';')[1].strip())
                    addd.append(line.split(';')[2].strip())
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900