dictionary - Python Tkinter Menu Command Not Working -
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 'app' menu. I want to have a series in the menu that corresponds to the key of the dictionary. When I click on the command, I want the default web browser to open and navigate to the URL in the App dictionary for that particular key. Instead, when I execute the code, the browser is opening the first URL in the application dictionary without any click. help please!
Imported webbrowser from imported #RailLinks are on pages on intranet Apps = {'Google': 'http: //www.google.com/', 'Yahoo': 'http: / /www.yahoo.com/ '} DRP openApp (appURL): webbrowser.open (appURL, new = 1, autoraise = 1) any root = tc () menubar = menu (root) root.cong (menu = menubar) App menu = App menu for app in app (menubar): appsMenu.add_command (label = app, command = openApp (apps [app]) menubar.add_cascade (label = 'apps', menu = appsMenu) root.mainloop () < / Code>
The command parameter that needs to be wrapped in call functions IMEprop = "text">
appsMenu.add_command (label = app, command = openApp (apps [app])) One Lambda < In addition, in order to prevent them from being told immediately, the command bound within a loop requires a looping variable as the original argument so that each time the right value can bind. appsMenu.add_command (label = app, command = lambda app = app: open-end (app [app]))
Comments
Post a Comment