473,395 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Dynamic command on Menu items?

(Python newbie alert..only 1 week's experience)

I want to create several menu items based upon a config file. In this
config file are label, function and a parameter. I want to show label
in the menu, then when it's chosen, call function with the given
parameter.

How can I do the correct equivalent of the following (which definitely
doesn't work)?

l='Zooks'
f='func'
p='Got Zooks'
M.menu.add_command(label=l, command=lambda: f(p))

so that when I pick 'Zooks' from the menu, func gets called with 'Got
Zooks'.
Joe
Jul 18 '05 #1
2 1741

You could do it like this (untested):

class FunClosure:
def __init__(self, f, args):
self.f = f
self.args = args
def __call__(self):
self.f(self.args)

M.menu.add_command(label=l, command=FunClosure(f, [p]))

--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
"Diez B. Roggisch" <de*********@web.de> wrote in message news:<cg*************@news.t-online.com>...
You could do it like this (untested):

class FunClosure:
def __init__(self, f, args):
self.f = f
self.args = args
def __call__(self):
self.f(self.args)

M.menu.add_command(label=l, command=FunClosure(f, [p]))

Sorry...no work. It says str object is not callable.

I would def. appreciate any refinement. If not, thanks anyway for trying.
Joe
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris Murphy via DotNetMonster.com | last post by:
Hi all, I'm just wondering if any one can help me with this development issue I'm having. I've created a customized treeview control to handle the particular tasks to which I'll be using it. Within...
4
by: Bob Homes | last post by:
In VB6, I used a system, which I loved, whereby I assigned a "helpId" to each menu item; that way, you could rest the cursor on the item (without actually running it) and then press F1 to get...
0
by: =?Utf-8?B?QmlzaG95?= | last post by:
Hi All, I have a Right to Left web page with asp.net 2.0 containing a horizontal menu. The menu is right to left as the page. The problem is the submenu items or the dynamic menu items are...
1
by: xpnctoc | last post by:
Here's the 30,000-ft. view: I wrapped an asp:Menu control in an ascx control. When I try to dynamically populate the menu in the ascx control, the items appear, but clicking on them fails to trigger...
2
by: andylotus | last post by:
Hi People I have a WinForm program. The UI contains a ToolStripDropdownButton, which is associate a list of menu items of ToolStripMenuItem, created dynamically. Upon different scenarios of user...
3
by: =?Utf-8?B?ZWFndWlsYXI=?= | last post by:
Hi, I am trying to dynamically generate a menu, based on entries on a text or xml file. The text file contains the "tree" after which the menu will need to be created. Something like the...
2
by: Andrus | last post by:
To reproduce, run code, open file menu, press up and down arrows to move out of menu. Menu items are scrolled and blank items appears in end. I need to change visibility of menu items at...
1
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got one Context Menu named mi_EasterEggs with three (3) menu items: * mi_FontArial * mi_FontCourier * mi_RawData All menu items have their Visible properties set to False when the form...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.