Python Tkinter Menu Command Not Working

前端 未结 1 1855
有刺的猬
有刺的猬 2021-01-17 02:21

I am trying to execute the following code in Python 2.6.5. What I want to do is show a main window with an \'Applications\' menu. I want the menu to have a series of command

1条回答
  •  一生所求
    2021-01-17 03:02

     appsMenu.add_command(label=app, command=openApp(Apps[app]))
    

    Command parameters that call functions need to be wrapped in a lambda, to prevent them from being called right away. Additionally, commands bound within a for loop need the looping variable as a default argument, in order for it to bind the right value each time.

     appsMenu.add_command(label=app, command=lambda app=app: openApp(Apps[app]))
    

    0 讨论(0)
提交回复
热议问题