Python Forum
Binding Complex data to Combobox
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Binding Complex data to Combobox
#1
Hi All,

In Customer table have two columns "ID" and "Name"

I want to bind the Customer information to Combobox, as Values I set Name property.

My question is once I change the index of Combobox, how can I get the ID property value based on the Name.
Reply
#2
this is pretty vague, please show code, this would be very helpful
which GUI?
Reply
#3
GUI : tkinter

Default Way ....
import tkinter as tk
from tkinter import ttk
 
app = tk.Tk() 
app.geometry('200x100')

labelTop = tk.Label(app,
                    text = "Choose your favourite month")
labelTop.grid(column=0, row=0)

comboExample = ttk.Combobox(app, 
                            values=[
                                    "January", 
                                    "February",
                                    "March",
                                    "April"])
pprint(dict(comboExample)) 
comboExample.grid(column=0, row=1)
comboExample.current(1)

print(comboExample.current(), comboExample.get())

app.mainloop()
Expected ....

import tkinter as tk
from tkinter import ttk
 
app = tk.Tk() 
app.geometry('200x100')

labelTop = tk.Label(app,
                    text = "Choose your favourite month")
labelTop.grid(column=0, row=0)

comboExample = ttk.Combobox(app, 
                            values=[(1,"January"),(2,"February"),(3,"March"),(4,"April")])
pprint(dict(comboExample)) 
comboExample.grid(column=0, row=1)
comboExample.current(1)

print(comboExample.current(), comboExample.get())

app.mainloop()
Question

In C# we use Value Member and Display Member
we Set 1, 2 ... as Value Member
Set January, .... as Display Member

When the application run shows January , .... but when we change the select index we can get value Member easily

So how can we same that in python using tkinter
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating Complex Color Spectrum Plot From Data JoeDainton123 2 945 Sep-15-2020, 08:09 AM
Last Post: DPaul
  Selection and display of data by combobox LagratteCchouette 10 3,617 Mar-02-2020, 06:34 PM
Last Post: ibreeden
  Binding not explicitly declared happening karkas 4 1,374 Aug-05-2019, 05:09 PM
Last Post: karkas
  Reading data into a Combobox from a .CSV file KevinBrown 7 4,890 Apr-14-2019, 11:30 AM
Last Post: KevinBrown
  QSqlRelationalTableModel: how do I save combobox data? panoss 2 4,635 Feb-08-2017, 08:13 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020