Python Forum
Unable pass the proper row number to Menubutton command
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable pass the proper row number to Menubutton command
#2
You need to freeze the value of the passed argument, otherwise lambda tries to pull the variable from the current scope.
        for choice in drop_down:
            menu_items[row_pos][choice] = IntVar(value=0)
            menus[row_pos].add_checkbutton(label=choice, variable=menu_items[row_pos][choice],
                                 onvalue=1, offvalue=0,
                                 command=lambda x=row_pos:printValues(x))
You should also take a look at functools.partial. I find partial often works better than lambda for this sort of thing.
Reply


Messages In This Thread
RE: Unable pass the proper row number to Menubutton command - by deanhystad - Jul-19-2020, 06:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] proper way of coding ebooczek 3 2,366 Feb-20-2022, 10:22 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020