Q:

Using a variable from a tkinter entry box to select a dictionary value

I am fairly new to Python having only written one other program using tkinter. In this program I am trying to allow the user to enter the element in an entry box they are looking for and the isotope of that element in another entry box. Using dictionaries to display the isotopes and percentages for each element. Then i want to use the value associated with the dict and key entered to do some math.  The problem I am having is that when I run the program it gives me an IndexError: string index out of range.  When I change the line saying 'f = e1.get()' to 'f=Ti' it works and assigns the dict to f, but when I try to use the entry from e1 to make the var f the same as dict Ti it does not work.
from tkinter import *

window=Tk()

window.geometry("560x500")

window.title("MSD")

e1 = StringVar()
c1 = IntVar()

Ti ={46 : '.0825',
     47 : '.0744',
     48 : '.7372',
     49 : '.0541',
     50 : '.0518'}

def  start():
    f = e1.get()
    g = c1.get()
    print(f)
    print(g)
    c = 1 - float(f[g])
    e = 1/c
    print(c)
    d = e * .7372
    print(d)

label2 = Label(window,text= 'elements:',font=('arial,20,bold'))
label2.place(x=10,y=75)

label8 = Label(window,text= 'overlaps:',font=('arial,20,bold'))
label8.place(x=10,y=125)

button1=Button(window,text='Start',width=12,bg='brown',fg='white',command=start)
button1.place(x=100,y=470)

entry4= Entry(window,textvar=e1,width=7)
entry4.place(x=10, y=100)
entry26= Entry(window,textvar=c1,width=7)
entry26.place(x=10, y=150)

window.mainloop()

A:

To me, it sounds like you need to make nested dictionaries (that is to say, dictionaries within a dictionary.)
See my example:
from tkinter import *

window=Tk()
window.geometry("560x500")
window.title("MSD")

e1 = StringVar()
c1 = IntVar()

master = {
    'Ti' : {
        46 : '.0825',
        47 : '.0744',
        48 : '.7372',
        49 : '.0541',
        50 : '.0518'},
    'O' : {
        16 : '.9976',
        17 : '.0004',
        18 : '.0020'},
    'N' : {
        14 : '.9960',
        15 : '.0040'}
        }

def  start():
    f = e1.get()
    g = c1.get()
    element = master[f]
    print(element)
    abundance = element[g]
    print(abundance)

label2 = Label(window,text= 'elements:',font=('arial,20,bold'))
label2.place(x=10,y=75)

label8 = Label(window,text= 'overlaps:',font=('arial,20,bold'))
label8.place(x=10,y=125)

button1=Button(window,text='Start',width=12,bg='brown',fg='white',command=start)
button1.place(x=100,y=470)

entry4= Entry(window,textvar=e1,width=7)
entry4.place(x=10, y=100)
entry26= Entry(window,textvar=c1,width=7)
entry26.place(x=10, y=150)

window.mainloop()

I don't know enough chemistry to really know what you were going for here, but this should get you started.
See how the 'master' dictionary contains an entry for different elements they could type in, and those entries then have a dictionary that can be called on as well.
When they are called upon in start(), it polls the entry fields and then finds which element dictionary to pull from 'master' and then grabs the number from that.
You could shorten that by just putting abundance = master[f][g] if you like.
I hope that is what you were shooting for; feel free to ask more questions.

