0

in Python (using Tkinter for GUI) I want to take the selected items (strings) from 2 dropdown menus and concatenate them. (done already) The resulting string will match a dictionary that I have already defined and will contain the pertinent information. ATM referencing the resulting string (which is now the same as an existing dictionary) isn't working. Ex:

sizeschedule = {'1': 'one', '2': 'two'}

# After the dropmenu selection occurs I now have these in StringVars:

firstdropdown = 'size'

seconddropdown = 'schedule'

combined = firstdropdown + seconddropdown  # gives 'sizeschedule'

print(combined['1'])  # Want that to give me 'one' (from dict value of '1')

1 Answers1

0

You could create a dropmenu_dict that contains sizeschedule:

>>> sizeschedule = {'1': 'one', '2': 'two'}
>>> dropmenu_dict = {'sizeschedule': sizeschedule}
>>> first_dropdown = 'size'
>>> second_dropdown = 'schedule'
>>> combined_dropdown = first_dropdown + second_dropdown
>>> dropmenu_dict[combined_dropdown]['1']
'one'
Sash Sinha
  • 18,743
  • 3
  • 23
  • 40
  • Thank you, sir. I'm going to try utilizing that. BTW, you are on the ball! lol. Took you about 45 seconds :) I wasn't expecting anything at all, much less something so quickly. Thanks! – Multiple Use Labor Element Nov 12 '21 at 15:53
  • 1
    It worked. Thank you. Someone should have done this years ago. They have us referencing 6 different Excel files using 12-character lookup codes (ex: AAZZZRESCSDD) to find the weights etc for about 10000 things in a Bill of Mats. With your (nested dictionary?) code I should be able to build the framework for a bespoke GUI program that just lets you pull up all pertinent info by selecting just 2 dropdown boxes. (building the DB will take a while but still.. that's just a bit of finite data entry) Again, Thanks! – Multiple Use Labor Element Nov 12 '21 at 16:22