Tkinter how to update second combobox automatically according this combobox
<p>I have encountered an issue with combobox updates in Tkinter Python.</p>

<p>I have two comboboxes:</p>

<ul>
<li>combobox <code>A</code> with <code>values =['A','B','C']</code> and</li>
<li>combobox <code>B</code></li>
</ul>

<p>What i want is that:</p>

<ul>
<li><p>when value <code>A</code> is selected in combobox <code>A</code> then in combobox <code>B</code> show the values <code>['1','2','3']</code></p></li>
<li><p>when value <code>B</code> is selected in combobox <code>A</code> then in combobox <code>B</code> show the values <code>['11','12','13']</code></p></li>
<li><p>when value <code>C</code> is selected in combobox <code>A</code> then in combobox <code>B</code> show the value s <code>['111','112','113']</code></p></li>
</ul>

<p>Currently part of my code as follows:</p>

<pre><code>def CallHotel(*args):
    global ListB
    if hotel.get()==ListA[0]
        ListB=ListB1
    if hotel.get()==ListA[1]
        ListB=ListB2
    if hotel.get()==ListA[2]
        ListB=ListB3

ListA=['A','B','C']

ListB1=['1','2','3']

ListB2=['11','12','13']

ListB3=['111','112','113']

ListB=ListB1

hotel = StringVar()
hotel.set('SBT')

comboboxA=ttk.Combobox(win0,textvariable=hotel,values=ListA,width=8)
comboboxA.bind("&lt;&lt;ComboboxSelected&gt;&gt;",CallHotel)
comboboxA.pack(side='left')  

stp = StringVar()
stp.set('STP')

comboboxB=ttk.Combobox(win0,textvariable=stp,values=ListB,width=15)
comboboxB.pack(side='left')
</code></pre>

<p>Actually you don't need the global variable <code>ListB</code>.  And you need to add <code>comboboxB.config(values=...)</code> at the end of <code>CallHotel()</code> to set the options of <code>comboboxB</code>:</p>

<pre><code>def CallHotel(*args):
    sel = hotel.get()
    if sel == ListA[0]:
        ListB = ListB1
    elif sel == ListA[1]:
        ListB = ListB2
    elif sel == ListA[2]:
        ListB = ListB3
    comboboxB.config(values=ListB)
</code></pre>

<p>And change the initial values of <code>comboboxB</code> to <code>ListB1</code> directly:</p>

<pre><code>comboboxB=ttk.Combobox(win0,textvariable=stp,values=ListB1,width=15)
</code></pre>

python tkinter combobox