用数据库值填充的组合框Tkinter

时间:2020-04-29 11:39:36

标签: python database tkinter combobox ttk

我尝试用数据库值填充组合框,而为optionmenu创建的一个ive很好。但是我无法使其与组合框一起使用。

    # Dictionary with options
    choices = c.execute('SELECT time date FROM data')
    tkvar.set('Select date and time') 

    lablemen= tk.Label(self, text = "Select start time", font=('helvetica', 20, 'bold'))
    lablemen.grid(row = 1 , column = 1)

    popupMenu = tk.OptionMenu(self, tkvar, *choices)
    popupMenu.config(font=('helvetica', 15, 'bold'))

    popupMenu.grid(row = 2 , column = 1)

我如何从选项菜单转到组合框?

我尝试过

  choices2 = c.execute('SELECT time date FROM data')

    cb = ttk.Combobox(self)
    cb.grid(row = 3, column = 1)

    cb['values'] = choices2

它给了我combobox result

1 个答案:

答案 0 :(得分:0)

想通了

    cb = ttk.Combobox(self)
    cb.grid(row = 3, column = 1)
    cblist = list()  

    for row in c.execute('SELECT time date FROM data'):

        cblist.append(row)

        cb['values'] = cblist