如何从数据库中获取combobox除1之外的所有值?

2024-10-03 19:24:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Python程序,最终用户在程序中插入他们的用户名和密码,然后程序将其插入MySQL数据库。然后程序可以从MySQL数据库中提取用户名,并在下拉列表Combobox中显示数据。但是有一个用户名我想对最终用户隐藏起来。这是我的代码:

try:
    connect()
    selectUsers = "select id, name from user"
    cursor.execute (selectUsers)

    bigfont = tkFont.Font(family = "Eurostile", size = 18)

    txtUsers = tk.StringVar()
    txtUsers.set("")
    drpUsers = ttk.Combobox(self, textvariable=txtUsers, state='readonly', font=("Eurostile", 18))#, bg = 'red', fg = 'white')
    root.option_add("*TCombobox*Listbox.font", bigfont)
    for (id, name) in cursor:
        valueStatement.append(id)
    drpUsers['values'] = valueStatement
    drpUsers.grid(column = 4, row = 4)#, padx = 5)
    closeConnect()
except:
    tkMessageBox.showinfo("Database Error", "ERR004 - There was an error communicating with the database")

Tags: name程序id数据库mysqlcursor用户名font