Jan-08-2022, 08:15 AM
I could use some help with tkinter comboboxes, and populating the combobox from a database. First question is, will the combobox accept a dictionary like key/value structure? Like (1,"Task Example 1"). I want to select based on a shown phrase, but return and do further processing with an associated index/key value. If the tkinter combobox can't do that, I have to try some other GUI framework.
Second question is, what is the proper phrasing to populate a combobox when taking data from a dataframe? I've tried everything, including converting a dataframe to a dictionary, and can't get it to work properly. Usually I get one column, with a separate line item for each word of the phrase, rather than the whole phrase on a line. I'm tried what seems like scores of different addressing approaches to the dataframe, with no luck, so I just left the addressing/slice info off below.
I've tried tracking down answers on several websites, including this one, but the information is always specific to that poster's code, and never seems transferable to mine.
Here is some sample data, in case someone needed it:
"TaskID","Requester","Headline"
6,"David","Set up SQL Server to use Python"
8,"David","Make Python talk to sql server"
Second question is, what is the proper phrasing to populate a combobox when taking data from a dataframe? I've tried everything, including converting a dataframe to a dictionary, and can't get it to work properly. Usually I get one column, with a separate line item for each word of the phrase, rather than the whole phrase on a line. I'm tried what seems like scores of different addressing approaches to the dataframe, with no luck, so I just left the addressing/slice info off below.
I've tried tracking down answers on several websites, including this one, but the information is always specific to that poster's code, and never seems transferable to mine.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import sqlite3 import pandas as pd import tkinter as tk from tkinter import ttk cnxn = sqlite3.connect( 'E:/taskmanager/taskmanager.db' ) cbodf = pd.read_sql_query( 'Select TaskID, Headline from MainTasks' , cnxn) root = tk.Tk() root.title( "Task Manager" ) root.geometry( "500x300+50+50" ) current_var = tk.StringVar() cboTask = ttk.Combobox(root, textvariable = current_var) cboTask[ 'values' ] = cbodf cboTask.pack(fill = tk.X, padx = 5 , pady = 15 ) root.mainloop() |
"TaskID","Requester","Headline"
6,"David","Set up SQL Server to use Python"
8,"David","Make Python talk to sql server"