0

I want to populate combobox with only one item if the name of the item appears more than one in the tuple only one name should appear.Also if the name is one in the tuple then the one should appear.

For example With my tuple i have sally which is appearing twice and i want only one to to inserted in the combobox

I will appreciate your assistance to do that.

from tkinter import *
from tkinter import ttk


rows = ((1, 'ben', 'journalism', 18), (2, 'sally', 'performing arts', 22), 
(3,"dan","information technology",32),
(2, 'ben', 'footballer', 70),(2, 'sally', 'arts', 56),(3,"dan","technology",52),(20,"frank","technology",52)


root = Tk()
root.geometry("200x200")

cb = ttk.Combobox(root)
cache = list()

for row in rows:
    cache.append(row[1])
    cb['values'] = cache

cb.pack()

root.mainloop()
LAS
  • 179
  • 4
  • 14
  • Possible duplicate of [How do you remove duplicates from a list in whilst preserving order?](https://stackoverflow.com/questions/480214/how-do-you-remove-duplicates-from-a-list-in-whilst-preserving-order) – Aran-Fey Apr 03 '18 at 16:12

2 Answers2

0

You could create a set() of the names, then use that to populate the combo box

krflol
  • 1,105
  • 7
  • 12
0

There are two values of sally in rows, and it adds them both - you can change this with a simple if statement inside the loop.

for row in rows:
    if row[1] not in cache:
        cache.append(row[1])
Crawley
  • 600
  • 2
  • 8
  • 15