israel-dryer / ttkbootstrap

A supercharged theme extension for tkinter that enables on-demand modern flat style themes inspired by Bootstrap.
MIT License
1.86k stars 374 forks source link

Add dictionary-values support for some widgets #333

Open gitseba4 opened 2 years ago

gitseba4 commented 2 years ago

Is your feature request related to a problem? Please describe.

For some widgets eg Combobox or Spinbox I've an idea to add to support dictionaries for values field. Currently it's only possible for tuples or lists. A dictionary would be perfect for working with databases.

Describe the solution you'd like

For example we have the following code snippet:

vehicle_brands = {1: 'Opel', 2: 'Seat', 3: 'Ford', 4: 'Toyota'}
vehicle_brand_sv = ttk.StringVar()

cb = ttk.Combobox(root, values=vehicle_brands, textvariable=vehicle_brand_sv)

For this case the combobox shows only dictionary-values, but the textvariable returns dictionary-key (alternatively key-value pair). For tuples or lists it works the old way.

Describe alternatives you've considered

In stackoverflow I found few alternatives:

But each of these solutions is inconvenient to use.

Additional context

No response

israel-dryer commented 2 years ago

@gitseba4, can you explain more what this would look like? Are you displaying the value, but the selection is associated with a key?

gitseba4 commented 2 years ago

Exactly, for the example above it would look like this: image

When we select the Seat item the vehicle_brand_sv variable should return 2 or optionally (2, 'Seat').

print(vehicle_brand_sv.get()) => 2
print(vehicle_brand_sv.get()) => (2, 'Seat')
israel-dryer commented 2 years ago

I'll add this to the roadmap on Version 2.0 which I'm working on now.