How do I populate tkinter drop-down box with data retrieved from my SQLite database? How do I populate tkinter drop-down box with data retrieved from my SQLite database? tkinter tkinter

How do I populate tkinter drop-down box with data retrieved from my SQLite database?


You could define movieList array somewhere in your code and then append the strings created in for loop to the movieList array:

movieList = []...for row in rows:        data = "%s %s %s %s %s" % (row["Id"], row["Title"], row["Date"], row["Time"], row["Duration"])        movieList.append(data)        print data

(As a side note, you could leave out row["Id"] and row["Duration"] fields,as the former is not really important to your users and the latter is redundant)

Building the drop-down menu is easy then, using OptionMenu widget; here is a minimal example with hard-coded values, the movieList of yours will be constructed dynamically in the aforementioned for loop:

from Tkinter import *movieList = ["1 Frozen 06/15 11:35 95", "3 Frozen 06/18 11:35 95",        "4 Frozen 06/30 11:25 95", "5 Frozen 07/02 11:45 95",        "6 Frozen 07/05 12:30 95"]master = Tk()option = StringVar(master)option.set(movieList[0]) # Set the first value to be the default optionw = apply(OptionMenu, (master, option) + tuple(movieList))w.pack()mainloop()

You can get the the chosen option then by calling get() method:

option.get()