Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Problem with "for" loop and "command" arg of CTkOptionMenu

$
0
0

Well, I have a nested dictionary:

d = {'id': {'a': CTkButton(), 'b': CTkButton(), 'c': CtkOptionMenu()},'id': {'a': CTkButton(), 'b': CTkButton(), 'c': CtkOptionMenu()}     ...    }

where id is:

  • row index
  • key of other global dict
  • etc.

I need to put this index to

def lexicon_callback(choice, k):

function (second arg). As you might guess, I create this dict through a loop. So I write this:

for key in var.old_lang.keys():    # here is some code    self.lang_dictionary_edit_entities[key]['lex'] = customtkinter.CTkOptionMenu(                    self.lang_dictionary_edit_frame, height=100,                    values=list(var.lexicon.keys()), command=lambda choice:                     lexicon_callback(choice, key)                )

The problem is that no matter what option menu I use, lambda function always put the last key ("41" in my case) in the "k" variable of lexicon_callback. I can understand why, but don't know, what to do with this situation.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>