Click here to Skip to main content
14,486,704 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am trying to make a simple tkinter with two combobox but value of one combobox is getting replicated in other combobox.

What I have tried:

import tkinter as tk
from tkinter import ttk
from tkinter import messagebox
import pandas as pd
import sqlite3
# Creating tkinter window
conn = sqlite3.connect('test.db')
print('Opened Database successfully');
tempAge = []
Salary = []
cursor = conn.execute('''Select * from Company''')
for row in cursor:
    tempAge.append(row[2])
    Salary.append(row[4])
data_dict = {'name': pd.Series(tempAge), 'age':pd.Series(Salary)}
dframe = pd.DataFrame(data_dict)
window = tk.Tk()
window.title('Combobox')
window.geometry('500x250')

# label text for title
ttk.Label(window, text="GFG Combobox Widget",
          background='green', foreground="white",
          font=("Times New Roman", 15)).grid(row=0, column=1)

# label
ttk.Label(window, text="Select the Age :",
          font=("Times New Roman", 10)).grid(column=0,
                                             row=5, padx=10, pady=25)

# Combobox creation
n = tk.StringVar()
agechoosen = ttk.Combobox(window, width=27, textvariable=n)
salchoosen = ttk.Combobox(window, width=27, textvariable=n)
# print("dframe['name']", dframe['name'])
# agechoosen['values'] = (tempAge)
agechoosen['values'] = (tempAge)
salchoosen['values'] = (Salary)
ageVar=''
salVar=''
def salComboSelect():
    if salchoosen.current()==-1:
        s=0
    else:
        salVar = salchoosen.get()
        messagebox.showinfo('Message',str(salVar))
def comboselect():
    if agechoosen.current()==-1 and salchoosen.current()==-1:
        s=0
    else:
        ageVar=agechoosen.get()
        salVar = salchoosen.get()
        tempStr = str(ageVar)+" & "+str(salVar)
        messagebox.showinfo('Message',str(tempStr))
        # print(monthchoosen.current(), monthchoosen.get())
button = ttk.Button(window, text='Submit', command=comboselect, width=20)
ttk.Label(window, text="Select the Age :",
          font=("Times New Roman", 10)).grid(column=0,
                                             row=5, padx=10, pady=25)
# print(monthchoosen.selection_get())
# monthchoosen['values'] = (pd.Series(tempAge))
# Adding combobox drop down list
# monthchoosen['values'] = (' January',
#                           ' February',
#                           ' March',
#                           ' April',
#                           ' May',
#                           ' June',
#                           ' July',
#                           ' August',
#                           ' September',
#                           ' October',
#                           ' November',
#                           ' December')
agechoosen.grid(column=1, row=5)
salchoosen.grid(column=1, row=6)
button.grid(column=1, row=7)
agechoosen.current()
window.mainloop()
Posted
Updated 23-Mar-20 20:22pm
Comments
Richard MacCutchan 24-Mar-20 5:44am
   
Use your debugger to see exactly what values are being captured into the two lists.

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100