Dictionaries Question

I am getting a KeyError error>

====================================
 ChangeToyType >>  ToyType =  Flexible  || Orientation =  Top
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files (x86)\Thonny\lib\tkinter\__init__.py", line 1921, in __call__
    return self.func(*args)
  File "C:\Users\rchrd\Dropbox\DartScreenShots RN_Machine\SmackerCode\Python Code\SmackerCode_TST.py", line 786, in Alignment
    ChangeToyType(toytype_options.get(),Orientation_options.get())
  File "C:\Users\rchrd\Dropbox\DartScreenShots RN_Machine\SmackerCode\Python Code\SmackerCode_TST.py", line 534, in ChangeToyType
    Toy_Sel = Toy_Decode[ToyType,Orientation,'Toy_Value']
KeyError: ('Flexible', 'Top', 'Toy_Value')

Here the function that throwing the error>>>

def ChangeToyType(ToyType, Orientation):
    
    global Toy_Sel_Pins
    global Toy_Sel
    global DIR_Value
    global DIR_Pin
    global Toy_Pin_Table

# Decode user selceted toy selction to machine settings



    Toy_Decode = {'Rigid':{
                        'Right Half Swing':{
                                            'DIR_Value': CCW,
                                            'Toy_Value': 0
                                            },
                         'Right Full Swing':{
                                            'DIR_Value': CCW,
                                            'Toy_Value': 1
                                            },
                          'Left Half Swing':{
                                            'DIR_Value': CW,
                                            'Toy_Value': 0
                                            },
                        'Left Full Swing':{ 
                                        'DIR_Value': CW,
                                        'Toy_Value': 1
                                         }
                       },
            'Flexible':{
                        'Right':{
                                'DIR_Value': 1,
                                'Toy_Value': 2
                                },
                        'Left':{
                                'DIR_Value': 0,
                                'Toy_Value': 2
                               },
                        'TOP': { 
                                'DIR_Value': 0,
                                'Toy_Value': 3
                                }
                       }
                     
             }
    
#Debug Point
    print()
    print("====================================")
    print(" ChangeToyType >>  ToyType = ", ToyType, " || Orientation = ", Orientation)
    
    Toy_Sel = Toy_Decode[ToyType,Orientation,'Toy_Value']
    print('Toy Sel >> ', Toy_Sel)
                                               
 # Now the user input decoded set the GPIO pins to tell contoller the Toy Type   
 #   GPIO.output(Toy_Sel_Pins, Toy_Pin_Table[Toy_Sel])
    GPIO.output(Toy_Sel_Pins, Toy_Pin_Table[Toy_Sel])
                                            
# OK the toy type has been defined so tell logic ontroler DIR direction	
#    GPIO.output(DIR_Pin,DIR_Value)
    GPIO.output(DIR_Pin, Toy_Decode[ToyType,Orientation,'DIR_Value'])

    

#Tell Cntroller to run the Alignment task
    print(" Telling controler to run Alignment task (12/[1,1,0,0])")
    GPIO.output(IntensitySelect_Pins,{1,1,0,0})

#Debug Point
    print("Exiting ChangeToyType >> Toy_Sel = ", Toy_Sel , " || DIR_Value = ", DIR_Value)


The question is what did I do wrong?

Thank you for you for sharing your wisdom with me. :grinning: :grinning:

Toy_Sel = Toy_Decode[ToyType,Orientation,'Toy_Value']

Replace that with

Toy_Sel = Toy_Decode[ToyType][Orientation]['Toy_Value']

Thank you your suggestion work perfect…