Python Forum
[Tkinter] Update a combobox - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] Update a combobox (/thread-23678.html)



Update a combobox - LagratteCchouette - Jan-12-2020

Hello,

Please, how do I update a combobox so that after entering a data item I return it to the drop-down list without having to restart the form?

My Combobox :

def cmb_theme(event=None):
    connexion = sqlite3.connect('mnesis.db')
    cursor = connexion.cursor()
    cursor.execute('SELECT theme_theme FROM tb_theme ORDER BY theme_theme')
    data = []
    for row in cursor.fetchall():
        data.append(row[0])
    return data
My function Save :

def save_theme(theme_theme):
    """ Insert in database """
    try:
        connection = sqlite3.connect('mnesis.db')  # Connection à la BdD
        cursor = connection.cursor() 
        new_theme = (cursor.lastrowid, theme_theme)  
        cursor.execute('INSERT INTO tb_theme VALUES(?,?)', new_theme)

    except Exception as e:
        print("ERREUR", e)
        connection.rollback()
    finally:
        cursor.close()
        connection.commit()
        connection.close()

        # Delete textbox after records
        entry_theme.delete('1.0', END)