-1

So simply there is no errors but the for loop is not working :

from tkinter import ttk
from tkinter import *
dic={'af': 'afrikaans', 'sq': 'albanian', 'am': 'amharic', 'ar': 'arabic'}
c=ttk.Combobox(values=list(dic.values()));c.grid(row=1,column=2)
j=c.current()
def blinta() :
    global j,s,dic
    print('1')
    for key,value in dic.items() :
        if str(j)==str(value):
            s=str(key)
            print(s)
vb=Button(text='translate',command=blinta).grid(row=1,column=3,pady=10)
  • 3
    This is much too vague. Define "not working". Better yet, please provide a [mcve], preferably one that doesn't involve `tkinter` since the GUI is unlikely to be the problem. First get the logic right, then worry about how to display it. – John Coleman May 10 '20 at 11:43
  • Also, what is the point of things like `s = str(key)`? You don't need to convert strings to strings and, in any event, you don't need to convert nonstrings to strings before printing them since `print()` will do an needed conversion. – John Coleman May 10 '20 at 11:53
  • 1
    You should move `j=c.current()` into `blinta()`. – acw1668 May 10 '20 at 12:03
  • 1
    Does this answer your question? [AttributeError: NoneType object has no attribute](https://stackoverflow.com/a/1101765/7414759) – stovfl May 10 '20 at 12:38

1 Answers1

1

Try this:

for key in dic.keys():
    if str(j)==str(dic[key]):
        s=str(key)
        print(s)
Alchimie
  • 426
  • 4
  • 12