From jepler at unpythonic.net Sat Aug 1 14:54:49 2009 From: jepler at unpythonic.net (Jeff Epler) Date: Sat, 1 Aug 2009 07:54:49 -0500 Subject: [Tkinter-discuss] tkFileDialog.askopenfilenames returns unicode string instead of tuple in python 2.62 In-Reply-To: <4A71FD5F.7070309@unixcluster.dk> References: <4A71FD5F.7070309@unixcluster.dk> Message-ID: <20090801125449.GA29255@unpythonic.net> As a workaround, I believe you can use input_files = root.tk.splitlist(input_files) which will correctly deal with filenames that contain embedded characters that have special meaning in Tcl. Jeff From boivie at hotmail.com Fri Aug 7 23:34:58 2009 From: boivie at hotmail.com (boivie) Date: Fri, 7 Aug 2009 14:34:58 -0700 (PDT) Subject: [Tkinter-discuss] command for dynamic buttons Message-ID: <24872360.post@talk.nabble.com> Hello! I'm making an application with lots of similar buttons. But I can't figure out how to make the command unique for each button. I tried to follow the advice in http://mail.python.org/pipermail/python-list/2002-July/152242.html this old message, but every button still gives the same output. class Program: def __init__(self, ruta): bokst = ['?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?'] i = 1 for option in bokst: laddaKnapp = lambda index=0, obj=self: obj.tryck(option) knapp = Button(self.nere, text=str(option), command=laddaKnapp) knapp.grid(row=1, column=i) i = i + 1 def tryck(self, bokstav): self.currText.set(bokstav) return I found how to do it in pygtk in http://www.pygtk.org/pygtk2tutorial/examples/clipboard.py this example , but I've not been able to find a singel example of dynamic buttons in tkinter. -- View this message in context: http://www.nabble.com/command-for-dynamic-buttons-tp24872360p24872360.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ggpolo at gmail.com Sat Aug 8 00:06:54 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Fri, 7 Aug 2009 19:06:54 -0300 Subject: [Tkinter-discuss] command for dynamic buttons In-Reply-To: <24872360.post@talk.nabble.com> References: <24872360.post@talk.nabble.com> Message-ID: 2009/8/7 boivie : > Hello! I'm making an application with lots of similar buttons. But I can't > figure out how to make the command unique for each button. I tried to follow > the advice in this old message, but every button still gives the same > output. > > class Program: > def __init__(self, ruta): > > bokst = ['?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?'] > > i = 1 > for option in bokst: > laddaKnapp = lambda index=0, obj=self: obj.tryck(option) > knapp = Button(self.nere, text=str(option), command=laddaKnapp) > knapp.grid(row=1, column=i) > i = i + 1 > > def tryck(self, bokstav): > self.currText.set(bokstav) > return > > I found how to do it in pygtk in this example, but I've not been able to > find a singel example of dynamic buttons in tkinter. Actually this is not tkinter fault, and pygtk doesn't do magic here either. For instance, if you translated this to pygtk you would get this: import gtk def test(option): print option things = ['a', 'b', 'c', 'd'] win = gtk.Window() hbox = gtk.HBox() win.add(hbox) for indx, option in enumerate(things): cmd = lambda event: test(option) btn = gtk.Button(option) btn.connect('clicked', cmd) hbox.pack_start(btn) win.show_all() win.connect('destroy', gtk.main_quit) gtk.main() Which would always print 'd'. Of course you could change that "connect" to: btn.connect('clicked', test, option) which you would proceed to change the test callback to accept an event parameter as the first argument, but this code is really different. I didn't look at the email you pointed, but if the suggestion included there maps to the code you posted then the suggestion is wrong. import Tkinter def test(option): print option things = ['a', 'b', 'c', 'd'] root = Tkinter.Tk() for indx, option in enumerate(things): cmd = lambda opt=option: test(opt) btn = Tkinter.Button(text=option, command=cmd) btn.pack(side='left') root.mainloop() The line you are after is "cmd = lambda opt=option: test(opt)". If instead you do "cmd = lambda: test(option)" (which is equivalent to what the code you pasted was doing), then when this lambda executes it will have to grab the value of this name "option" from somewhere, which will be the last element from the things list. -- -- Guilherme H. Polo Goncalves From ggpolo at gmail.com Sat Aug 8 00:12:14 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Fri, 7 Aug 2009 19:12:14 -0300 Subject: [Tkinter-discuss] command for dynamic buttons In-Reply-To: References: <24872360.post@talk.nabble.com> Message-ID: 2009/8/7 Guilherme Polo : > 2009/8/7 boivie : ... > > import Tkinter > > def test(option): > ? ?print option > > things = ['a', 'b', 'c', 'd'] > > root = Tkinter.Tk() > > for indx, option in enumerate(things): You don't need indx neither enumerate here (same for the gtk code). I was going to use grid like you did, but in the end the pasted code didn't use. I hope this doesn't compromise understanding the problem described. > ? ?cmd = lambda opt=option: test(opt) > ? ?btn = Tkinter.Button(text=option, command=cmd) > ? ?btn.pack(side='left') > > root.mainloop() -- -- Guilherme H. Polo Goncalves From Cameron at phaseit.net Sat Aug 8 01:09:50 2009 From: Cameron at phaseit.net (Cameron Laird) Date: Fri, 7 Aug 2009 23:09:50 +0000 Subject: [Tkinter-discuss] command for dynamic buttons In-Reply-To: References: <24872360.post@talk.nabble.com> Message-ID: <20090807230950.GA32413@lairds.us> On Fri, Aug 07, 2009 at 07:06:54PM -0300, Guilherme Polo wrote: . . . > > Hello! I'm making an application with lots of similar buttons. But I can't > > figure out how to make the command unique for each button. I tried to follow . . . > I didn't look at the email you pointed, but if the suggestion included > there maps to the code you posted then the suggestion is wrong. > > import Tkinter > > def test(option): > print option > > things = ['a', 'b', 'c', 'd'] > > root = Tkinter.Tk() > > for indx, option in enumerate(things): > cmd = lambda opt=option: test(opt) > btn = Tkinter.Button(text=option, command=cmd) > btn.pack(side='left') > > root.mainloop() > > The line you are after is "cmd = lambda opt=option: test(opt)". If > instead you do "cmd = lambda: test(option)" (which is equivalent to > what the code you pasted was doing), then when this lambda executes it > will have to grab the value of this name "option" from somewhere, > which will be the last element from the things list. . . . Also, look for "Parameter-passing" in . From igor.e.novikov at gmail.com Sat Aug 8 09:28:35 2009 From: igor.e.novikov at gmail.com (Igor Novikov) Date: Sat, 8 Aug 2009 10:28:35 +0300 Subject: [Tkinter-discuss] ARGB/animated cursors for Tkinter widgets under X.org Message-ID: <23f7fc190908080028h7eb1a112t6b43877bcb577d37@mail.gmail.com> Hi all! We have released small python extension - tkXcursor. The package provides custom ARGB/animated cursor support for Tkinter widgets under X.org If anybody is interested, source code and short description are here: http://sk1project.org/viewpage.php?page_id=20 Regards, Igor Novikov sK1 Project http://sk1project.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From papieminem at yahoo.fr Fri Aug 14 20:27:58 2009 From: papieminem at yahoo.fr (papieminem) Date: Fri, 14 Aug 2009 11:27:58 -0700 (PDT) Subject: [Tkinter-discuss] How to direct a text on Tkinter Message-ID: <24976455.post@talk.nabble.com> HI On Tkinter we can only write from left to right. How to do , if we want to write from right to left for exmple or Vertically or Diagonally. Thank -- View this message in context: http://www.nabble.com/How-to-direct-a-text-on-Tkinter-tp24976455p24976455.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From srilyk at gmail.com Sun Aug 16 03:40:49 2009 From: srilyk at gmail.com (Wayne) Date: Sat, 15 Aug 2009 20:40:49 -0500 Subject: [Tkinter-discuss] How to direct a text on Tkinter In-Reply-To: <24976455.post@talk.nabble.com> References: <24976455.post@talk.nabble.com> Message-ID: <333efb450908151840x4fee36ceq6295b8ed10cf08d@mail.gmail.com> On Fri, Aug 14, 2009 at 1:27 PM, papieminem wrote: > > HI > On Tkinter we can only write from left to right. > How to do , if we want to write from right to left for exmple or Vertically > or Diagonally. > Thank You'd have to reverse your text and align it to the right side. Vertically you'll need newlines after every character, and diagonally you'll need newlines+spaces. HTH, Wayne -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael.odonnell at uam.es Sun Aug 16 09:05:10 2009 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Sun, 16 Aug 2009 09:05:10 +0200 Subject: [Tkinter-discuss] How to direct a text on Tkinter In-Reply-To: <333efb450908151840x4fee36ceq6295b8ed10cf08d@mail.gmail.com> References: <24976455.post@talk.nabble.com> <333efb450908151840x4fee36ceq6295b8ed10cf08d@mail.gmail.com> Message-ID: <47e491110908160005v5d92d2a6s212898b9fe37973c@mail.gmail.com> For Vertical/Diagonal text: In Tcl/Tk 8.6, the Canavs widget allows text to be rotated 90 degrees (or other angle). Now, Python is still using 8.5 I believe. Does anyone know whether if you compile Python with only Tcl/Tk 8.6 installed, the resulting system will work? Mick On Sun, Aug 16, 2009 at 3:40 AM, Wayne wrote: > On Fri, Aug 14, 2009 at 1:27 PM, papieminem wrote: >> >> HI >> On Tkinter we can only write from left to right. >> How to do , if we want to write from right to left for exmple or >> Vertically >> or Diagonally. >> Thank > > You'd have to reverse your text and align it to the right side. Vertically > you'll need newlines after every character, and diagonally you'll need > newlines+spaces. > HTH, > Wayne > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > From ggpolo at gmail.com Sun Aug 16 16:27:21 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Sun, 16 Aug 2009 11:27:21 -0300 Subject: [Tkinter-discuss] How to direct a text on Tkinter In-Reply-To: <47e491110908160005v5d92d2a6s212898b9fe37973c@mail.gmail.com> References: <24976455.post@talk.nabble.com> <333efb450908151840x4fee36ceq6295b8ed10cf08d@mail.gmail.com> <47e491110908160005v5d92d2a6s212898b9fe37973c@mail.gmail.com> Message-ID: 2009/8/16 Michael O'Donnell : > For Vertical/Diagonal text: > In Tcl/Tk 8.6, the Canavs widget allows text to be rotated 90 degrees > (or other angle). > > Now, Python is still using 8.5 I believe. Does anyone know whether if you > compile Python with only Tcl/Tk 8.6 installed, the resulting system will work? > It will work Michael, but before compiling you have to do a minor tweak on setup.py around like 1540. Just add a '8.6' and '86' on the list that contains other version numbers so it will also accept compiling _tkinter with Tcl/Tk 8.6. > Mick > -- -- Guilherme H. Polo Goncalves From ggpolo at gmail.com Sun Aug 16 16:52:50 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Sun, 16 Aug 2009 11:52:50 -0300 Subject: [Tkinter-discuss] How to direct a text on Tkinter In-Reply-To: References: <24976455.post@talk.nabble.com> <333efb450908151840x4fee36ceq6295b8ed10cf08d@mail.gmail.com> <47e491110908160005v5d92d2a6s212898b9fe37973c@mail.gmail.com> Message-ID: 2009/8/16 Guilherme Polo : > 2009/8/16 Michael O'Donnell : >> For Vertical/Diagonal text: >> In Tcl/Tk 8.6, the Canavs widget allows text to be rotated 90 degrees >> (or other angle). >> >> Now, Python is still using 8.5 I believe. Does anyone know whether if you >> compile Python with only Tcl/Tk 8.6 installed, the resulting system will work? >> > > It will work Michael, but before compiling you have to do a minor > tweak on setup.py around like 1540. Just add a '8.6' and '86' on the > list that contains other version numbers so it will also accept > compiling _tkinter with Tcl/Tk 8.6. > If you are using python trunk or the py3k branch to do custom compilations of _tkinter then update it and the above adjust won't be necessary anymore. >> Mick >> > > > -- > -- Guilherme H. Polo Goncalves > -- -- Guilherme H. Polo Goncalves From sxn02 at yahoo.com Sun Aug 16 20:32:57 2009 From: sxn02 at yahoo.com (Sorin Schwimmer) Date: Sun, 16 Aug 2009 11:32:57 -0700 (PDT) Subject: [Tkinter-discuss] How to direct a text on Tkinter Message-ID: <12103.30254.qm@web56005.mail.re3.yahoo.com> I suggest to have a look at tkZinc (www.tkzinc.org). It is a Canvas++, so to speak, and I was able to make small maps of the "how to find us" kind. Some street names were shown horizontally, some vertically; I understand you need something similar. Good luck, SxN __________________________________________________________________ The new Internet Explorer? 8 - Faster, safer, easier. Optimized for Yahoo! Get it Now for Free! at http://downloads.yahoo.com/ca/internetexplorer/ From klappnase at web.de Sun Aug 16 22:44:06 2009 From: klappnase at web.de (Michael Lange) Date: Sun, 16 Aug 2009 22:44:06 +0200 Subject: [Tkinter-discuss] How to direct a text on Tkinter In-Reply-To: <12103.30254.qm@web56005.mail.re3.yahoo.com> References: <12103.30254.qm@web56005.mail.re3.yahoo.com> Message-ID: <20090816224406.251fbfcc.klappnase@web.de> On Sun, 16 Aug 2009 11:32:57 -0700 (PDT) Sorin Schwimmer wrote: > I suggest to have a look at tkZinc (www.tkzinc.org). It is a Canvas+ > +, so to speak, and I was able to make small maps of the "how to find > us" kind. Some street names were shown horizontally, some vertically; > I understand you need something similar. Hmmm, I first thought the OP meant if there is a way to write right to left or vertically in a Text widget ? If this is the case I am afraid there is not much hope, I am not absolutely sure, though. Regards Michael From mark_eastwood at ntlworld.com Tue Aug 18 13:44:25 2009 From: mark_eastwood at ntlworld.com (thicket) Date: Tue, 18 Aug 2009 04:44:25 -0700 (PDT) Subject: [Tkinter-discuss] How do I identify which menu item has bee selected? Message-ID: <25023156.post@talk.nabble.com> Hi - am using python 2.6 and Tkinter 8.5. I would like to know how to identify which 'menu item' has been selected from a cascaded menu. The cascaded menu menu items are variable and created on the fly. The idea is to use a common callback for all menu items, the callback function then determines which selection was made and runs the appropriate function. I have tried binding an event to the selection and then trying to get some sort of info from the event object (event.widget()) but this appears to return info about the menu class instance and not about it's menu items. I've used Java in the past - and if I recall correctly - a menu-item is a class, in python it seems to be an attribute(list entry) of the menu class - in which case - how do I interrogate it if I do not know it's index? Any help is appreciated - it's starting to do my head in!! -- View this message in context: http://www.nabble.com/How-do-I-identify-which-menu-item-has-bee-selected--tp25023156p25023156.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From papieminem at yahoo.fr Tue Aug 18 14:34:26 2009 From: papieminem at yahoo.fr (papieminem) Date: Tue, 18 Aug 2009 05:34:26 -0700 (PDT) Subject: [Tkinter-discuss] How to direct a text on Tkinter In-Reply-To: References: <24976455.post@talk.nabble.com> <333efb450908151840x4fee36ceq6295b8ed10cf08d@mail.gmail.com> <47e491110908160005v5d92d2a6s212898b9fe37973c@mail.gmail.com> Message-ID: <25023922.post@talk.nabble.com> Can i use Tcl/Tk 8.6 with python 2.5 ? And how to do it? i am new and french;-) -- View this message in context: http://www.nabble.com/How-to-direct-a-text-on-Tkinter-tp24976455p25023922.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From bieffe62 at gmail.com Wed Aug 19 10:53:07 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Wed, 19 Aug 2009 10:53:07 +0200 Subject: [Tkinter-discuss] How do I identify which menu item has bee selected? In-Reply-To: <25023156.post@talk.nabble.com> References: <25023156.post@talk.nabble.com> Message-ID: 2009/8/18 thicket > > Hi - am using python 2.6 and Tkinter 8.5. > > I would like to know how to identify which 'menu item' has been selected > from a cascaded menu. > > The cascaded menu menu items are variable and created on the fly. The idea > is to use a common callback for all menu items, the callback function then > determines which selection was made and runs the appropriate function. > > I have tried binding an event to the selection and then trying to get some > sort of info from the event object (event.widget()) but this appears to > return info about the menu class instance and not about it's menu items. > > I've used Java in the past - and if I recall correctly - a menu-item is a > class, in python it seems to be an attribute(list entry) of the menu class > - > in which case - how do I interrogate it if I do not know it's index? > > Any help is appreciated - it's starting to do my head in!! Hi Mark, to build a menu you have: - create a menubar, which is a Menu object f type menubar: mbar = Menu( type='menubar', ... ) - create menus, which also are Menu objects, and adding to the menubar by using the add_cascade method of the menu bar: menu = menu(master=se,f.mbar, ... ) mbar.add_cascade( menu ) - populate the menu using the add_command method of the menu: menu.add_command( label='Do something', command= do_command_callback ) Now, in Tkinter there is no possibility to specify parameters to pass a callback, but there are several ways to do it, which you can find following the links from here: http://tkinter.unpy.net/wiki/Widgets/Button (section parameter passing: it refers to button callbacks but the same applies for menus). I personally tend to suggest functools.partial, which you should use like this to have the same callback called with a differemt menu item: menu.add_command( label='Do something', command= functools.partial(do_command_callback, 1 ) menu.add_command( label='Do something else', command= functools.partial(do_command_callback, 2 ) ) In case you need more examples of how to use tk widgets with python, have a look at this suite of the programs that I wrote some time ago (code is a bit old but still working with latest python versions): http://tkinter.unpy.net/wiki/A_tour_of_Tkinter_widgets P.S : in case you don't know, unlike Java, Python has not a 'default widget set', that you must use if you are coding in python. Instead, you can use several among the most popular widget toolkits (Gtk+, Qt, ... ), even Swing if you use the java version of python (Jython), which is a bit behind as language version (stable supports Python 2.5, beta supports Python 2.6). Tkinter has the advantage of being bundled with python (for the others you have to dounload and install additional modules) and surely is suitable for many tasks, especially if for you functionality is more important than look (although with a bit of effort Tk GUI can also look cool, see for instance aMSN, a clone of mSN Messanger written using the same toolkit of Tkinter, but not in Python). Sorry for the verbosity (feeling bored :-), hope I managed to help in the process Ciao ------ Francesco -------------- next part -------------- An HTML attachment was scrubbed... URL: From ggpolo at gmail.com Wed Aug 19 13:41:22 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Wed, 19 Aug 2009 08:41:22 -0300 Subject: [Tkinter-discuss] How do I identify which menu item has bee selected? In-Reply-To: <25023156.post@talk.nabble.com> References: <25023156.post@talk.nabble.com> Message-ID: 2009/8/18 thicket : > > Hi - am using python 2.6 and Tkinter 8.5. > > I would like to know how to identify which 'menu item' has been selected > from a cascaded menu. > > The cascaded menu menu items are variable and created on the fly. The idea > is to use a common callback for all menu items, the callback function then > determines which selection was made and runs the appropriate function. > > I have tried binding an event to the selection and then trying to get some > sort of info from the event object (event.widget()) but this appears to > return info about the menu class instance and not about it's menu items. > I will try something here, but since you didn't post what you tried it may not be what you want. I always see my own code indented on email, but if that is not the case for everyone then it is better to move it to some paste bin. Anyway, below is an attempt to do what you want but there is a problem with it. If you can't guarantee that new entries are added to the end, then the code needs to be adapted. import Tkinter root = Tkinter.Tk() menu = Tkinter.Menu(root, tearoff=False) def test(parent, index): def cb(): print parent.entrycget(index, 'label') return cb def build_menu(descr, parent): for item in descr: if isinstance(item, list): menu = Tkinter.Menu(root, tearoff=False) parent.add_cascade(label=item[0], menu=menu) build_menu(item[1], menu) else: indx = parent.index('last') if indx is None: indx = 0 else: indx += 1 parent.insert_command(index=indx, label=item, command=test(parent, indx)) menudescr = [['File', [['Recent file list', ['a', 'b', 'c']]]]] build_menu(menudescr, menu) root['menu'] = menu root.mainloop() -- -- Guilherme H. Polo Goncalves From ggpolo at gmail.com Wed Aug 19 13:49:15 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Wed, 19 Aug 2009 08:49:15 -0300 Subject: [Tkinter-discuss] How do I identify which menu item has bee selected? In-Reply-To: References: <25023156.post@talk.nabble.com> Message-ID: 2009/8/19 Francesco Bochicchio : > P.S : in case you don't know, unlike Java, Python has not a 'default widget > set', that you must use if you are coding in python. > Instead, you can use several among the most popular widget toolkits (Gtk+, > Qt, ... ), even Swing if you use the java version of python (Jython), which > is a bit behind as language version (stable supports Python 2.5, beta > supports Python 2.6). I don't see how is that different from Java, there are gtk bindinds and qt bindings for Java too. > Tkinter has the advantage of being bundled with python (for the others you > have to dounload and install additional modules) Doesn't that turn tkinter into the 'default widget set' ? > and surely is suitable for > many tasks, especially if for you functionality is more important than look > (although with a bit of effort Tk GUI can also look cool, see for instance > aMSN, a clone of mSN Messanger written using the same toolkit of Tkinter, > but not in Python). > Ciao > ------ > Francesco -- -- Guilherme H. Polo Goncalves From Cameron at phaseit.net Wed Aug 19 14:01:15 2009 From: Cameron at phaseit.net (Cameron Laird) Date: Wed, 19 Aug 2009 12:01:15 +0000 Subject: [Tkinter-discuss] How do I identify which menu item has bee selected? In-Reply-To: References: <25023156.post@talk.nabble.com> Message-ID: <20090819120115.GB31904@lairds.us> On Wed, Aug 19, 2009 at 10:53:07AM +0200, Francesco Bochicchio wrote: . . [much valuable detail] . > P.S : in case you don't know, unlike Java, Python has not a 'default widget > set', that you must use if you are coding in python. > Instead, you can use several among the most popular widget toolkits (Gtk+, > Qt, ... ), even Swing if you use the java version of python (Jython), which > is a bit behind as language version (stable supports Python 2.5, beta > supports Python 2.6). > Tkinter has the advantage of being bundled with python (for the others you > have to dounload and install additional modules) and surely is suitable for > many tasks, especially if for you functionality is more important than look > (although with a bit of effort Tk GUI can also look cool, see for instance > aMSN, a clone of mSN Messanger written using the same toolkit of Tkinter, > but not in Python). . . . I don't understand the distinction you're drawing between Python and Java. What is Java's "default widget set"? AWT? JFC? But what about, for example, Thinlet? From mark_eastwood at ntlworld.com Wed Aug 19 14:42:02 2009 From: mark_eastwood at ntlworld.com (thicket) Date: Wed, 19 Aug 2009 05:42:02 -0700 (PDT) Subject: [Tkinter-discuss] How do I identify which menu item has bee selected? In-Reply-To: References: <25023156.post@talk.nabble.com> Message-ID: <25043302.post@talk.nabble.com> Thanks Francesco, Guilherme - you've both given me plenty to experiment with (and learn :-)). I have a 'partial' solution to what I'm trying to achieve (code snippet below) ......... self.menubar = Menu(self.frm) # create the variable 'Action' sub-menu list # each sub-menu entry will have an (on)value which corresponds to it's DB tablename (self.tables[value - 1]) self.muVar=IntVar() self.mnth_mu=Menu(self.menubar, tearoff=0) self.on=IntVar() x=0 # Strip out the month_yr part of the DB tablename (e.g. 04_April_09) and create a radiobutton entry on the # menu for each table that currently exists - a table is only created at the start of a month for mnth in self.tables: st=mnth.split("_",1)[1] self.mnth_mu.add_radiobutton(label=st, variable=self.muVar, value=self.on.get(), command=self.alt_cmd) x+=1 self.on.set(x) # create the 'Action' menu list self.act_mu = Menu(self.menubar, tearoff=0) self.act_mu.add_command(label="Low stock - closing less monthly sales", command=self.low_stock) self.act_mu.add_command(label="Profit and Loss", command=self.pandl) self.act_mu.add_cascade(label="Stock/Order History", menu=self.mnth_mu) self.act_mu.add_cascade(label="Top two sellers by quantity", menu=self.mnth_mu) self.act_mu.add_cascade(label="Top two earners", menu=self.mnth_mu) self.act_mu.add_cascade(label="Bottom two sellers by quantity", menu=self.mnth_mu) self.act_mu.add_cascade(label="Bottom two earners", menu=self.mnth_mu) self.menubar.add_cascade(label="Actions", menu=self.act_mu) # display the menu parent.config(menu=self.menubar) ........ def alt_cmd(self): # Determine the selection, match it to the correct tablename then call appropriate function to generate the sql print self.muVar.get() ........ The issue is that all the 'Actions' after and including Stock/Order history will display the same sub-menu (self.mnth_mu). The code as it stands enables me to identify which month has been selected for a particular 'Action' but not which 'Action' it refers to i.e. works fine if self.mnth.mu is used only once. A solution is to create a separate menu for each 'Action' - I am averse to doing this because the sub-menu for each action that requires a sub-menu is identical and yes I'm a bit of a lazy programmer! I was hoping to - whatever the level of a menu - when a selection is made - to be able to identify the 'Action' and the 'Month' selected. I hope this makes sense ... I shall look into what you both have said cheers -- View this message in context: http://www.nabble.com/How-do-I-identify-which-menu-item-has-bee-selected--tp25023156p25043302.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From ggpolo at gmail.com Wed Aug 19 15:32:01 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Wed, 19 Aug 2009 10:32:01 -0300 Subject: [Tkinter-discuss] How do I identify which menu item has bee selected? In-Reply-To: <25043302.post@talk.nabble.com> References: <25023156.post@talk.nabble.com> <25043302.post@talk.nabble.com> Message-ID: 2009/8/19 thicket : > > I have a > 'partial' solution to what I'm trying to achieve (code snippet below) > ......... > > The issue is that all the 'Actions' after and including Stock/Order history > will display the same sub-menu (self.mnth_mu). > > The code as it stands enables me to identify which month has been selected > for a particular 'Action' but not which 'Action' it refers to i.e. works > fine if self.mnth.mu is used only once. > Well, my real suggestion would be to change this application. Don't you think it is weird that when you select a month for a specific action, all the other actions will have the same month selected ? How can you know which one is active by looking in the menus ? Even if you changed it to have multiple tcl variables, you still wouldn't know which exact thing is active. Nevertheless, I gave it a try and the code is below. It does create a new menu for each action, but it is just about the same effort of creating a single one. import Tkinter root = Tkinter.Tk() def test(action): def cb(): print month_var.get(), action return cb def create_month_menu(action): month_menu = Tkinter.Menu(action_menu, tearoff=False) for month in ('Jan', 'Feb', 'Mar'): month_menu.add_radiobutton(label=month, variable=month_var, command=test(action)) return month_menu menu = Tkinter.Menu(tearoff=False) action_menu = Tkinter.Menu(menu, tearoff=False) month_var = Tkinter.StringVar() for action in ('A1', 'A2'): action_menu.add_cascade(label=action, menu=create_month_menu(action)) menu.add_cascade(label='Actions', menu=action_menu) root['menu'] = menu root.mainloop() -- -- Guilherme H. Polo Goncalves From bieffe62 at gmail.com Wed Aug 19 16:15:34 2009 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Wed, 19 Aug 2009 16:15:34 +0200 Subject: [Tkinter-discuss] How do I identify which menu item has bee selected? In-Reply-To: <20090819120115.GB31904@lairds.us> References: <25023156.post@talk.nabble.com> <20090819120115.GB31904@lairds.us> Message-ID: 2009/8/19 Cameron Laird > On Wed, Aug 19, 2009 at 10:53:07AM +0200, Francesco Bochicchio wrote: > . > . > [much valuable detail] > . > > P.S : in case you don't know, unlike Java, Python has not a 'default > widget > > set', that you must use if you are coding in python. > > Instead, you can use several among the most popular widget toolkits > (Gtk+, > > Qt, ... ), even Swing if you use the java version of python (Jython), > which > > is a bit behind as language version (stable supports Python 2.5, beta > > supports Python 2.6). > > Tkinter has the advantage of being bundled with python (for the others > you > > have to dounload and install additional modules) and surely is suitable > for > > many tasks, especially if for you functionality is more important than > look > > (although with a bit of effort Tk GUI can also look cool, see for > instance > > aMSN, a clone of mSN Messanger written using the same toolkit of Tkinter, > > but not in Python). > . > . > . > I don't understand the distinction you're drawing between Python > and Java. What is Java's "default widget set"? AWT? JFC? But > what about, for example, Thinlet? Since the OP seemed to link too close Python to Tkinter ( or at list I read it that way ) I just wanted to clarify that Tkinter is not the only choice when it comes to GUI in python. I draw the parallel because last time I worked with Java (which was some time ago ) Swing was almost the only option (with AWT being obsoleted and other bindings being non-exixtent ). Ciao ------ FB -------------- next part -------------- An HTML attachment was scrubbed... URL: From ggpolo at gmail.com Wed Aug 19 16:27:34 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Wed, 19 Aug 2009 11:27:34 -0300 Subject: [Tkinter-discuss] How do I identify which menu item has bee selected? In-Reply-To: References: <25023156.post@talk.nabble.com> <20090819120115.GB31904@lairds.us> Message-ID: 2009/8/19 Francesco Bochicchio : > > > 2009/8/19 Cameron Laird >> >> On Wed, Aug 19, 2009 at 10:53:07AM +0200, Francesco Bochicchio wrote: >> ? ? ? ? ? ? ? ? ? ? ? ?. >> ? ? ? ? ? ? ? ? ? ? ? ?. >> ? ? ? ? ? ? ? ?[much valuable detail] >> ? ? ? ? ? ? ? ? ? ? ? ?. >> > P.S : in case you don't know, unlike Java, Python has not a 'default >> > widget >> > set', that you must use if you are coding in python. >> > Instead, you can use several among the most popular widget toolkits >> > (Gtk+, >> > Qt, ... ), even Swing if you use the java version of python (Jython), >> > which >> > is a bit behind as language version (stable supports Python 2.5, beta >> > supports Python 2.6). >> > Tkinter has the advantage of being bundled with python (for the others >> > you >> > have to dounload and install additional modules) and surely is suitable >> > for >> > many tasks, especially if for you functionality is more important than >> > look >> > (although with a bit of effort Tk GUI can also look cool, see for >> > instance >> > aMSN, a clone of mSN Messanger written using the same toolkit of >> > Tkinter, >> > but not in Python). >> ? ? ? ? ? ? ? ? ? ? ? ?. >> ? ? ? ? ? ? ? ? ? ? ? ?. >> ? ? ? ? ? ? ? ? ? ? ? ?. >> I don't understand the distinction you're drawing between Python >> and Java. ?What is Java's "default widget set"? ?AWT? ?JFC? ?But >> what about, for example, Thinlet? > > Since the OP seemed to link too close Python to Tkinter ( or at list I read > it that way ) I don't see how, honestly. He started saying "Hi - am using python 2.6 and Tkinter 8.5.", how does that link too close Python to Tkinter ? Plus, this is a tkinter list, I don't know what are you expecting (hopefully not that people post offtopic questions just to show they use another toolkit). > Ciao > ------ > FB > Regards, -- -- Guilherme H. Polo Goncalves From Cameron at phaseit.net Wed Aug 19 16:40:56 2009 From: Cameron at phaseit.net (Cameron Laird) Date: Wed, 19 Aug 2009 14:40:56 +0000 Subject: [Tkinter-discuss] How do I identify which menu item has bee selected? In-Reply-To: References: <25023156.post@talk.nabble.com> <20090819120115.GB31904@lairds.us> Message-ID: <20090819144056.GA13754@lairds.us> On Wed, Aug 19, 2009 at 04:15:34PM +0200, Francesco Bochicchio wrote: > > . > > . > > . > > I don't understand the distinction you're drawing between Python > > and Java. What is Java's "default widget set"? AWT? JFC? But > > what about, for example, Thinlet? > > > Since the OP seemed to link too close Python to Tkinter ( or at list I read > it that way ) I just wanted to clarify that Tkinter > is not the only choice when it comes to GUI in python. I draw the parallel > because last time I worked with Java (which was some time ago ) Swing was > almost the only option (with AWT being obsoleted and other bindings being > non-exixtent ). . . . I entirely agree that Python supports a wealth of GUI toolkits; 'fact, I've mentioned before in publications that Python is ef- fectively the single language with the broadest span in that regard. From mark_eastwood at ntlworld.com Thu Aug 20 00:41:13 2009 From: mark_eastwood at ntlworld.com (thicket) Date: Wed, 19 Aug 2009 15:41:13 -0700 (PDT) Subject: [Tkinter-discuss] How do I identify which menu item has bee selected? In-Reply-To: References: <25023156.post@talk.nabble.com> <25043302.post@talk.nabble.com> Message-ID: <25053122.post@talk.nabble.com> Well, my real suggestion would be to change this application. Don't you think it is weird that when you select a month for a specific action, all the other actions will have the same month selected ? yeah I know - I've used a radiobutton to see if it could be used instead of a cascaded menu. The 'partial' bit is that I was able to to identify the selection through the use the variables but as you say - it is not a good way to go about this. I've just run your code and it is exactly what I'm trying to do :-D however I ideally want to use add_cascade() instead of add_radiobutton() .. my problem is that a menu object does not provide for use of variables and so far, using variables is the only way I've managed to get a 'partial' solution albeit a bad one!! Therefore the solution I've been trying to achieve is what your code does but using add_cascade(). Failing that a rethink of the app. thanks again cheers -- View this message in context: http://www.nabble.com/How-do-I-identify-which-menu-item-has-bee-selected--tp25023156p25053122.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From ggpolo at gmail.com Thu Aug 20 00:52:32 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Wed, 19 Aug 2009 19:52:32 -0300 Subject: [Tkinter-discuss] How do I identify which menu item has bee selected? In-Reply-To: <25053122.post@talk.nabble.com> References: <25023156.post@talk.nabble.com> <25043302.post@talk.nabble.com> <25053122.post@talk.nabble.com> Message-ID: 2009/8/19 thicket : > > I've just run your code and it is exactly what I'm trying to do :-D however > I ideally want to use add_cascade() instead of add_radiobutton() .. my > problem is that a menu object does not provide for use > of variables and so far, using variables is the only way I've managed to get > a 'partial' solution albeit a bad one!! > > Therefore the solution I've been trying to achieve is what your code does > but using add_cascade(). ?Failing that a rethink of the app. > Did you mean add_command instead of add_cascade ? It is possible to do what you want, the first code I pasted didn't use Tcl variables so maybe you could try adjusting it to your needs. > thanks again > cheers > > -- -- -- Guilherme H. Polo Goncalves From mark_eastwood at ntlworld.com Thu Aug 20 01:42:01 2009 From: mark_eastwood at ntlworld.com (thicket) Date: Wed, 19 Aug 2009 16:42:01 -0700 (PDT) Subject: [Tkinter-discuss] How do I identify which menu item has bee selected? In-Reply-To: References: <25023156.post@talk.nabble.com> <25043302.post@talk.nabble.com> <25053122.post@talk.nabble.com> Message-ID: <25053797.post@talk.nabble.com> Sorry my fault - have not explained it well - what I mean is the 'variable' coption that is available in add_checkbutton() and add_radiobutton() but not in add_cascade(). It is through the use of the 'variable' coption that the month selected is determined - knowing the month that has been selected is crucial in determining which function to run. I could not see a way of using a cascaded menu and still determine the month selected. Having said that - seeing the way that you have written your code (I must say I do like!) - I reckon I've been approaching this from the wrong angle and am fairly sure that I can adapt it to what I need - this I'll do. There is always the option to simplify it all e.g. include a menubutton on the menubar from which a month can be selected then run all 'actions' against that month - though not as flexible from a user perspective. Will work on what you have shown me. cheers -- View this message in context: http://www.nabble.com/How-do-I-identify-which-menu-item-has-bee-selected--tp25023156p25053797.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From itsmilesdavis at gmail.com Mon Aug 31 17:40:07 2009 From: itsmilesdavis at gmail.com (John Jack) Date: Mon, 31 Aug 2009 11:40:07 -0400 Subject: [Tkinter-discuss] Create Buttons on the fly Message-ID: <7e7b6e9e0908310840g2f04364bj14ed42a39f4f4aa2@mail.gmail.com> Hello all, I have a long list of objects, which I print to a GUI. I want to filter this list, print the filtered list to the GUI, but maintain the ability to look at the previous lists. My program currently takes the list (L1), prints it to a Listbox, and adds a button (B1) for the list. Next, I filter the list, print the new filtered list (L2 subset of L1) to the same Listbox (removing the elements of L1 not in L2), and add an additional button for the new list. And so on... How do I find a way to associate the old list L1 to the command for the button (B1)? Note, I do not want to create a separate command for each button because I want to run an unlimited number of filters. I need to have B1 linked to L1, B2 linked to L2, B3 linked to L3, etc. Here is some relevant code (n.b., the whole project is much larger, so this is merely a snippet). #n.b., L from the description above is all_entities. So, L1 is all_entities[1], etc. #filter_group is an index tracking the current group to be filtered. #Filter the list def search_entities(self): tmp1 = askstring('Search Entity','Entity Type',initialvalue='gene') filtered = [] #Create sublist for ent in self.backend.all_entities[self.filter_group]: if ent.etype.endswith("findthisstring"): filtered.append(ent) #Store sublist self.backend.all_entities.append(filtered) self.filter_group += 1 self.add_filter_button() def add_filter_button(self): tmp = 'B%s' % self.filter_group filt = Button(self,text = tmp,command=self.fill_listbox(self)) filt.grid(row=3,column=self.filter_group,sticky=E) self.fill_listbox() def fill_listbox(self): #clear listbox if self.ent_listbox.size() > 0: self.ent_listbox.delete(0,END) #Restore list box for ent in self.backend.all_entities[self.filter_group]: self.ent_listbox.insert(END,ent.name) The way my code exists now, I would need to modify the variable filter_group when I click a button. How can I accomplish this? How do I tell filter_group to be 1 if I click button 1 and 2 if I click button 2? Sorry if this post is long. Let me know if you need more information. Python v2.6 (Linux) -------------- next part -------------- An HTML attachment was scrubbed... URL: From Cameron at phaseit.net Mon Aug 31 18:33:21 2009 From: Cameron at phaseit.net (Cameron Laird) Date: Mon, 31 Aug 2009 16:33:21 +0000 Subject: [Tkinter-discuss] Create Buttons on the fly In-Reply-To: <7e7b6e9e0908310840g2f04364bj14ed42a39f4f4aa2@mail.gmail.com> References: <7e7b6e9e0908310840g2f04364bj14ed42a39f4f4aa2@mail.gmail.com> Message-ID: <20090831163321.GB21515@lairds.us> On Mon, Aug 31, 2009 at 11:40:07AM -0400, John Jack wrote: . . . > I have a long list of objects, which I print to a GUI. I want to filter > this list, print the filtered list to the GUI, but maintain the ability to > look at the previous lists. > > My program currently takes the list (L1), prints it to a Listbox, and adds a > button (B1) for the list. Next, I filter the list, print the new filtered > list (L2 subset of L1) to the same Listbox (removing the elements of L1 not > in L2), and add an additional button for the new list. And so on... > > How do I find a way to associate the old list L1 to the command for the > button (B1)? Note, I do not want to create a separate command for each > button because I want to run an unlimited number of filters. I need to have > B1 linked to L1, B2 linked to L2, B3 linked to L3, etc. > > Here is some relevant code (n.b., the whole project is much larger, so this > is merely a snippet). > > #n.b., L from the description above is all_entities. So, L1 is > all_entities[1], etc. > #filter_group is an index tracking the current group to be filtered. > > #Filter the list > def search_entities(self): > tmp1 = askstring('Search Entity','Entity Type',initialvalue='gene') > filtered = [] > #Create sublist > for ent in self.backend.all_entities[self.filter_group]: > if ent.etype.endswith("findthisstring"): > filtered.append(ent) > > #Store sublist > self.backend.all_entities.append(filtered) > self.filter_group += 1 > self.add_filter_button() > > def add_filter_button(self): > tmp = 'B%s' % self.filter_group > filt = Button(self,text = tmp,command=self.fill_listbox(self)) > filt.grid(row=3,column=self.filter_group,sticky=E) > self.fill_listbox() > > def fill_listbox(self): > #clear listbox > if self.ent_listbox.size() > 0: > self.ent_listbox.delete(0,END) > #Restore list box > for ent in self.backend.all_entities[self.filter_group]: > self.ent_listbox.insert(END,ent.name) > > The way my code exists now, I would need to modify the variable filter_group > when I click a button. How can I accomplish this? How do I tell > filter_group to be 1 if I click button 1 and 2 if I click button 2? . . . The answer is implicit in , especially in the section titled "Parameter-passing". Is that enough of a hint for you to reach the answer on your own? Otherwise, I expect one of us will make time over the next thirty hours or so to provide an explicit coding. From itsmilesdavis at gmail.com Mon Aug 31 19:15:50 2009 From: itsmilesdavis at gmail.com (John Jack) Date: Mon, 31 Aug 2009 13:15:50 -0400 Subject: [Tkinter-discuss] Create Buttons on the fly In-Reply-To: <20090831163321.GB21515@lairds.us> References: <7e7b6e9e0908310840g2f04364bj14ed42a39f4f4aa2@mail.gmail.com> <20090831163321.GB21515@lairds.us> Message-ID: <7e7b6e9e0908311015v5580a0f9u82bd3128dd05bdde@mail.gmail.com> That is very helpful. I appreciate your expeditious response. Thanks, JJ. On Mon, Aug 31, 2009 at 12:33 PM, Cameron Laird wrote: > On Mon, Aug 31, 2009 at 11:40:07AM -0400, John Jack wrote: > . > . > . > > I have a long list of objects, which I print to a GUI. I want to filter > > this list, print the filtered list to the GUI, but maintain the ability > to > > look at the previous lists. > > > > My program currently takes the list (L1), prints it to a Listbox, and > adds a > > button (B1) for the list. Next, I filter the list, print the new > filtered > > list (L2 subset of L1) to the same Listbox (removing the elements of L1 > not > > in L2), and add an additional button for the new list. And so on... > > > > How do I find a way to associate the old list L1 to the command for the > > button (B1)? Note, I do not want to create a separate command for each > > button because I want to run an unlimited number of filters. I need to > have > > B1 linked to L1, B2 linked to L2, B3 linked to L3, etc. > > > > Here is some relevant code (n.b., the whole project is much larger, so > this > > is merely a snippet). > > > > #n.b., L from the description above is all_entities. So, L1 is > > all_entities[1], etc. > > #filter_group is an index tracking the current group to be filtered. > > > > #Filter the list > > def search_entities(self): > > tmp1 = askstring('Search Entity','Entity > Type',initialvalue='gene') > > filtered = [] > > #Create sublist > > for ent in self.backend.all_entities[self.filter_group]: > > if ent.etype.endswith("findthisstring"): > > filtered.append(ent) > > > > #Store sublist > > self.backend.all_entities.append(filtered) > > self.filter_group += 1 > > self.add_filter_button() > > > > def add_filter_button(self): > > tmp = 'B%s' % self.filter_group > > filt = Button(self,text = tmp,command=self.fill_listbox(self)) > > filt.grid(row=3,column=self.filter_group,sticky=E) > > self.fill_listbox() > > > > def fill_listbox(self): > > #clear listbox > > if self.ent_listbox.size() > 0: > > self.ent_listbox.delete(0,END) > > #Restore list box > > for ent in self.backend.all_entities[self.filter_group]: > > self.ent_listbox.insert(END,ent.name) > > > > The way my code exists now, I would need to modify the variable > filter_group > > when I click a button. How can I accomplish this? How do I tell > > filter_group to be 1 if I click button 1 and 2 if I click button 2? > . > . > . > The answer is implicit in http://tkinter.unpythonic.net/wiki/Widgets/Button >, especially > in the section titled "Parameter-passing". Is that enough of a > hint for you to reach the answer on your own? Otherwise, I > expect one of us will make time over the next thirty hours or so > to provide an explicit coding. > -------------- next part -------------- An HTML attachment was scrubbed... URL: