From alex.matyukhin at yandex.ru Fri Jun 1 22:50:39 2012 From: alex.matyukhin at yandex.ru (Alexander Matyukhin) Date: Fri, 1 Jun 2012 20:50:39 +0000 (UTC) Subject: [Tkinter-discuss] How to insert a string into a Text using Button Message-ID: Hello to all! I have a simple code, which use tkinter. It has a Text widget and two Buttons. First Button must insert string into text. But it dont do it. The string is inserted into text after start and the button don't react on click. Second button must close window and it do it normal. Where did I have an error? Code: #!//usr/bin/env python3.2 #_*_coding: utf-8_*_ import tkinter as tk def InsertToText (): text_widget.insert (1.0, 'Hello World!') # New window main_window = tk.Tk() # Text widget text_widget = tk.Text (main_window) text_widget.pack() # First button button_insert = tk.Button (main_window, text='Insert string', command=InsertToText()) button_insert.pack() # Second button button_close = tk.Button (main_window, text='Close', command=main_window.destroy) button_close.pack() main_window.mainloop() -- Alexander Matyukhin From bryan.oakley at gmail.com Fri Jun 1 23:19:34 2012 From: bryan.oakley at gmail.com (Bryan Oakley) Date: Fri, 1 Jun 2012 16:19:34 -0500 Subject: [Tkinter-discuss] How to insert a string into a Text using Button In-Reply-To: References: Message-ID: On Fri, Jun 1, 2012 at 3:50 PM, Alexander Matyukhin < alex.matyukhin at yandex.ru> wrote: > Hello to all! I have a simple code, which use tkinter. > It has a Text widget and two Buttons. First Button > must insert string into text. But it dont do it. > The string is inserted into text after start and the > button don't react on click. > Second button must close window and it do it normal. > Where did I have an error? > > > # First button > button_insert = tk.Button (main_window, > text='Insert string', command=InsertToText()) > Remove the () for the command attribute. It should be: ... command=InsertToText) The way you have it, you are calling InsertToText(), and the result of that call (None) is what is getting assigned to the command attribute of the button. -------------- next part -------------- An HTML attachment was scrubbed... URL: From matteo at matteolandi.net Sat Jun 2 15:02:24 2012 From: matteo at matteolandi.net (Matteo Landi) Date: Sat, 2 Jun 2012 15:02:24 +0200 Subject: [Tkinter-discuss] Deadlock on graceful exit In-Reply-To: References: <20120530222241.GB12763@MARble> Message-ID: On Thu, May 31, 2012 at 2:42 PM, Matteo Landi wrote: > On Thu, May 31, 2012 at 12:56 PM, Wayne Werner wrote: >> >> >> On Thu, 31 May 2012, Matteo Landi wrote: >> >>> Do you see anything wrong with the description presented above? ?Please >>> say so, >>> because I can't figure it out! >> >> >> Yes, though I have not looked at your code, if you're doing what you said >> and >> using threads in a Tkinter app. This will almost always lead to horrible, >> nasty >> bugs. Instead, use the .after() method in Tkinter, and let your app worry >> about >> timing/threading. > > Hi Wayne, > I'm currently using `after_idle` to schedule gui updates: ?is there > anything wrong in using it instead of `after`? > > > Cheers, > Matteo > > > -- > http://www.matteolandi.net/ I found the solution to the problem. Previously, I was invoking `Tk.after_idle` outside the mainloop thread, thinking it was thread-safe to do so; unfortunately I was wrong, and after implementing a solution based on a polling gui task and a synchronized queue shared with the working thread, everything started to work flawlessly. Cheers, Matteo -- http://www.matteolandi.net/ From list at qtrac.plus.com Thu Jun 7 18:18:25 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Thu, 7 Jun 2012 17:18:25 +0100 Subject: [Tkinter-discuss] Application window icon on Linux Message-ID: <20120607171825.19ba2c29@dino> Hi, I am struggling to get an application icon to show up on Linux. (Although it works perfectly on Windows.) I know this issue has come up before and I've followed the advice: I made the icon 16x16, XBM format, and prefixed the full path with '@'. I am using Python 3.2.2 and Tcl/Tk 8.5. Here is a complete example: #!/usr/bin/env python3 import os from tkinter import * from tkinter.ttk import * class Window(Frame): def __init__(self, parent): super().__init__(parent) quitButton = Button(self, text="Quit", command=self.master.destroy) quitButton.pack() self.pack() self.set_icon(os.path.join(os.getcwd(), "hello")) # hello.xbm, hello.ico; both 16x16 def set_icon(self, iconName): windowSystem = self.master.tk.call("tk", "windowingsystem") if windowSystem == "win32": # Windows iconName += ".ico" elif windowSystem == "x11": # Unix iconName = "@" + iconName + ".xbm" if windowSystem != "aqua" and os.path.isfile(iconName): print(iconName) self.master.iconbitmap(iconName) #self.master.wm_iconbitmap(iconName) also works app = Tk() app.title("Hello") Window(app) app.mainloop() This works perfectly on Windows 7. But on Linux (Debian & Ubuntu), I just get a default icon. The print() statement produces: @/home/mark/hello.xbm This hello.xbm file's contents are: #define hello_width 16 #define hello_height 16 static unsigned char hello_bits[] = { 0x00, 0x00, 0x0e, 0x70, 0x0e, 0x70, 0x0e, 0x70, 0x0e, 0x70, 0x0e, 0x70, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0x0e, 0x70, 0x0e, 0x70, 0x0e, 0x70, 0x0e, 0x70, 0x0e, 0x70, 0x0e, 0x70, 0x00, 0x00 }; Thanks! -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Python 3" - ISBN 0321680561 http://www.qtrac.eu/py3book.html From klappnase at web.de Thu Jun 7 19:01:32 2012 From: klappnase at web.de (Michael Lange) Date: Thu, 7 Jun 2012 19:01:32 +0200 Subject: [Tkinter-discuss] Application window icon on Linux In-Reply-To: <20120607171825.19ba2c29@dino> References: <20120607171825.19ba2c29@dino> Message-ID: <20120607190132.fdc17b2f.klappnase@web.de> Hi Mark, Thus spoketh Mark Summerfield unto us on Thu, 7 Jun 2012 17:18:25 +0100: > This works perfectly on Windows 7. But on Linux (Debian & Ubuntu), I > just get a default icon. The print() statement produces: > @/home/mark/hello.xbm I had to look twice myself, even if you showed the solution yourself in the sentence above: of course os.path.isfile('@/home/mark/hello.xbm') will always be False ;) If you change your set_icon() function to use a simple try...except instead of additional tests as in def set_icon(self, iconName): windowSystem = self.master.tk.call("tk", "windowingsystem") if windowSystem == "win32": # Windows iconName += ".ico" elif windowSystem == "x11": # Unix iconName = "@" + iconName + ".xbm" try: self.master.iconbitmap(iconName) except TclError: pass it should save you some headaches and (hopefully) work fine as long as the bitmap file is present. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Without followers, evil cannot spread. -- Spock, "And The Children Shall Lead", stardate 5029.5 From list at qtrac.plus.com Fri Jun 8 09:00:12 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Fri, 8 Jun 2012 08:00:12 +0100 Subject: [Tkinter-discuss] Application window icon on Linux In-Reply-To: <20120607190132.fdc17b2f.klappnase@web.de> References: <20120607171825.19ba2c29@dino> <20120607190132.fdc17b2f.klappnase@web.de> Message-ID: <20120608080012.52f1e3ef@dino> Hi Michael, OK that was silly of me! It works perfectly now -- thanks:-) BTW I haven't seen any nice pure Python ways to set the Windows taskbar icon (although it "just works" on Linux). -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Go" - ISBN 0321774639 http://www.qtrac.eu/gobook.html From list at qtrac.plus.com Mon Jun 11 17:58:55 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Mon, 11 Jun 2012 16:58:55 +0100 Subject: [Tkinter-discuss] Is it safe to use True/False for 1/0 in tkinter? Message-ID: <20120611165855.1b8aa8b5@dino> Hi, For tkinter methods that take 0 or 1 for true or false such as wm_overrideredirect(), is it safe to use Python's True and False builtins instead? Doing so seems to work, but just wanted to check. Thanks! -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Rapid GUI Programming with Python and Qt" - ISBN 0132354187 http://www.qtrac.eu/pyqtbook.html From wayne at waynewerner.com Tue Jun 12 13:11:28 2012 From: wayne at waynewerner.com (Wayne Werner) Date: Tue, 12 Jun 2012 06:11:28 -0500 (CDT) Subject: [Tkinter-discuss] Is it safe to use True/False for 1/0 in tkinter? In-Reply-To: <20120611165855.1b8aa8b5@dino> References: <20120611165855.1b8aa8b5@dino> Message-ID: On Mon, 11 Jun 2012, Mark Summerfield wrote: > Hi, > > For tkinter methods that take 0 or 1 for true or false such as > wm_overrideredirect(), is it safe to use Python's True and False > builtins instead? > > Doing so seems to work, but just wanted to check. I'm somewhat certain that it will work just fine, at least it does everywhere I've used it. My guess is the reason that it does work is because of Python's truthiness checks - 1, and any collection (string, list, tuple, set, dict... etc) that contain values are True. 0, None, and all empty collections are False. This makes it possible to write cleaner code (at least in my, and many other people's opinion) because instead of having to write: if len(mylist) == 0: #blah blah blah you can just write if mylist: #blah blah blah Which might surprise someone at first, but I think most (all?) people find it incredibly natural to use. I haven't done any tests, but I would make a guess that [Tt]kinter might do a truthiness conversion before passing the argument on to Tcl. At least in every case that I've used it it does for values of 1 and True... HTH, Wayne From klappnase at web.de Tue Jun 12 14:00:27 2012 From: klappnase at web.de (Michael Lange) Date: Tue, 12 Jun 2012 14:00:27 +0200 Subject: [Tkinter-discuss] Is it safe to use True/False for 1/0 in tkinter? In-Reply-To: References: <20120611165855.1b8aa8b5@dino> Message-ID: <20120612140027.add7adfe.klappnase@web.de> Hi, Thus spoketh Wayne Werner unto us on Tue, 12 Jun 2012 06:11:28 -0500 (CDT): > I'm somewhat certain that it will work just fine, at least it does > everywhere I've used it. I agree. Although I am too lazy to dig through the tkinter sources, I am quite sure that the tkapp object allows True / False as well as 0 / 1 (as integers) and their respective string counterparts as boolean values. I did a little experiment with getboolean() : >>> from Tkinter import * >>> root = Tk() >>> getboolean(1) 1 >>> getboolean('1') True >>> getboolean(True) True >>> getboolean('True') True >>> getboolean('true') True >>> getboolean(1.0) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 336, in getboolean return _default_root.tk.getboolean(s) TypeError: getboolean() argument 1 must be string, not float >>> getboolean('abc') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 336, in getboolean return _default_root.tk.getboolean(s) _tkinter.TclError: expected boolean value but got "abc" So it looks like any string that tk accepts as boolean is legal as well as 0 / 1 or True / False . Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Leave bigotry in your quarters; there's no room for it on the bridge. -- Kirk, "Balance of Terror", stardate 1709.2 From Cameron at phaseit.net Tue Jun 12 14:16:22 2012 From: Cameron at phaseit.net (Cameron Laird) Date: Tue, 12 Jun 2012 12:16:22 +0000 Subject: [Tkinter-discuss] Is it safe to use True/False for 1/0 in tkinter? In-Reply-To: <20120612140027.add7adfe.klappnase@web.de> References: <20120611165855.1b8aa8b5@dino> <20120612140027.add7adfe.klappnase@web.de> Message-ID: <20120612121622.GA13487@lairds.us> On Tue, Jun 12, 2012 at 02:00:27PM +0200, Michael Lange wrote: > Thus spoketh Wayne Werner > unto us on Tue, 12 Jun 2012 06:11:28 -0500 (CDT): > > > I'm somewhat certain that it will work just fine, at least it does > > everywhere I've used it. > > I agree. Although I am too lazy to dig through the tkinter sources, I am > quite sure that the tkapp object allows True / False as well as 0 / 1 (as > integers) and their respective string counterparts as boolean values. I > did a little experiment with getboolean() : . . . From klappnase at web.de Tue Jun 12 19:04:04 2012 From: klappnase at web.de (Michael Lange) Date: Tue, 12 Jun 2012 19:04:04 +0200 Subject: [Tkinter-discuss] Is it safe to use True/False for 1/0 in tkinter? In-Reply-To: <20120612121622.GA13487@lairds.us> References: <20120611165855.1b8aa8b5@dino> <20120612140027.add7adfe.klappnase@web.de> <20120612121622.GA13487@lairds.us> Message-ID: <20120612190404.aef51811.klappnase@web.de> Hi, Thus spoketh Cameron Laird unto us on Tue, 12 Jun 2012 12:16:22 +0000: > . > hmm, but this does not seem to apply to Tkinter, for example >>> root.overrideredirect([]) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1571, in wm_overrideredirect 'wm', 'overrideredirect', self._w, boolean)) _tkinter.TclError: expected boolean value but got "[]" >>> root.overrideredirect(0j) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1571, in wm_overrideredirect 'wm', 'overrideredirect', self._w, boolean)) _tkinter.TclError: expected boolean value but got "0j" >>> root.overrideredirect('') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1571, in wm_overrideredirect 'wm', 'overrideredirect', self._w, boolean)) _tkinter.TclError: expected boolean value but got "" but: >>> root.overrideredirect(0.0) >>> root.overrideredirect(0L) >>> root.overrideredirect(55) >>> whereas: >>> getboolean(0.0) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.1/tkinter/__init__.py", line 328, in getboolean return _default_root.tk.getboolean(s) TypeError: must be string, not float >>> getboolean(0L) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 336, in getboolean return _default_root.tk.getboolean(s) TypeError: getboolean() argument 1 must be string, not long so it actually looks like Tkinter behavior is not fully coherent here. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. I thought my people would grow tired of killing. But you were right, they see it is easier than trading. And it has its pleasures. I feel it myself. Like the hunt, but with richer rewards. -- Apella, "A Private Little War", stardate 4211.8 From list at qtrac.plus.com Wed Jun 13 08:36:04 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Wed, 13 Jun 2012 07:36:04 +0100 Subject: [Tkinter-discuss] Is it safe to use True/False for 1/0 in tkinter? In-Reply-To: <20120612190404.aef51811.klappnase@web.de> References: <20120611165855.1b8aa8b5@dino> <20120612140027.add7adfe.klappnase@web.de> <20120612121622.GA13487@lairds.us> <20120612190404.aef51811.klappnase@web.de> Message-ID: <20120613073604.1fcd78a5@dino> Hi Michael, On Tue, 12 Jun 2012 19:04:04 +0200 Michael Lange wrote: > Hi, [snip] > >>> root.overrideredirect(0.0) > >>> root.overrideredirect(0L) > >>> root.overrideredirect(55) > >>> > > whereas: > > >>> getboolean(0.0) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python3.1/tkinter/__init__.py", line 328, in getboolean > return _default_root.tk.getboolean(s) > TypeError: must be string, not float > >>> getboolean(0L) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 336, in getboolean > return _default_root.tk.getboolean(s) > TypeError: getboolean() argument 1 must be string, not long > > so it actually looks like Tkinter behavior is not fully coherent here. Shouldn't this count as a bug then? -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Go" - ISBN 0321774639 http://www.qtrac.eu/gobook.html From list at qtrac.plus.com Wed Jun 13 09:12:10 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Wed, 13 Jun 2012 08:12:10 +0100 Subject: [Tkinter-discuss] ttk.Spinbox missing? Message-ID: <20120613081210.74757ba0@dino> Hi, I have Python 3.2 with Tcl/Tk 8.5, but there doesn't seem to be a ttk.Spinbox widget even though that widget is part of Tcl/Tk 8.5: http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_spinbox.htm Why is that? -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Go" - ISBN 0321774639 http://www.qtrac.eu/gobook.html From klappnase at web.de Wed Jun 13 11:13:09 2012 From: klappnase at web.de (Michael Lange) Date: Wed, 13 Jun 2012 11:13:09 +0200 Subject: [Tkinter-discuss] Is it safe to use True/False for 1/0 in tkinter? In-Reply-To: <20120613073604.1fcd78a5@dino> References: <20120611165855.1b8aa8b5@dino> <20120612140027.add7adfe.klappnase@web.de> <20120612121622.GA13487@lairds.us> <20120612190404.aef51811.klappnase@web.de> <20120613073604.1fcd78a5@dino> Message-ID: <20120613111309.a8726215.klappnase@web.de> Hi, Thus spoketh Mark Summerfield unto us on Wed, 13 Jun 2012 07:36:04 +0100: > > >>> getboolean(0.0) > > Traceback (most recent call last): > > File "", line 1, in > > File "/usr/lib/python3.1/tkinter/__init__.py", line 328, in > > getboolean return _default_root.tk.getboolean(s) > > TypeError: must be string, not float > > >>> getboolean(0L) > > Traceback (most recent call last): > > File "", line 1, in > > File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 336, in getboolean > > return _default_root.tk.getboolean(s) > > TypeError: getboolean() argument 1 must be string, not long > > > > so it actually looks like Tkinter behavior is not fully coherent here. > > Shouldn't this count as a bug then? OTOH, if you look at >>> getboolean.__doc__ 'Convert true and false to integer values 1 and 0.' >>> Misc.getboolean.__doc__ 'Return a boolean value for Tcl boolean values true and false given as parameter.' >>> getboolean('true') True >>> We see that getboolean does what it promises (left aside that the default boolean return values in Python have changed from 0 / 1 to True / False by now). According to http://wiki.tcl.tk/16235 valid boolean values in Tcl are also yes, no, on, off, 0 or 1. In fact all of these seem to work, even case insensitive: >>> getboolean('on') True >>> getboolean('1') True >>> getboolean('yes') True >>> getboolean('yEs') True That the special values 0 / 1 (integers) and True / False are also accepted, seems to be a special undocumented extra feature, probably added so we can pass directly the return value of some Tkinter function to getboolean() without having to convert it into string first (as you can see it is done in the function definitions below). So maybe it is simply that my example function wasn't chosen wisely. The inconsistency seems to arise when getboolean() is used behind the scenes and behaves differently tha Tk, as in e.g. def wm_overrideredirect(self, boolean=None): """Instruct the window manager to ignore this widget if BOOLEAN is given with 1. Return the current value if None is given.""" return self._getboolean(self.tk.call( 'wm', 'overrideredirect', self._w, boolean)) Now if we do >>> root.overrideredirect(0.0) the float is passed to and obviously accepted by Tk, although (according to the wiki at least) it does not seem to be "correct" use of booleans in Tcl. Let's try another Tk method that wants a boolean: >>> root.tk_strictMotif(0.0) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 374, in tk_strictMotif 'set', 'tk_strictMotif', boolean)) TypeError: getboolean() argument 1 must be string, not float >>> And when we look at what goes on behind the scenes: def tk_strictMotif(self, boolean=None): """Set Tcl internal variable, whether the look and feel should adhere to Motif. A parameter of 1 means adhere to Motif (e.g. no color change if mouse passes over slider). Returns the set value.""" return self.tk.getboolean(self.tk.call( 'set', 'tk_strictMotif', boolean)) we see that it's Tk itself which is not consistent, because tk_strictMotif apparently returns the float where wm overrideredirect does not. Now, is this a bug? Hard to tell, I would not say so, because as long as we stick with the documented usage everything works as expected and I think we cannot seriously rely on undocumented features to work coherently in any case. However, coming back to the original question, as far as the 0/1 vs. True/False issue is affected, I guess that simply the Tkinter docs could use an update, as True/False have been the officially preferred bool values since 2.4 (or so) and are apparently supported by Tkinter. Probably there was just no one who found the time to do this (?). Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. The only solution is ... a balance of power. We arm our side with exactly that much more. A balance of power -- the trickiest, most difficult, dirtiest game of them all. But the only one that preserves both sides. -- Kirk, "A Private Little War", stardate 4211.8 From klappnase at web.de Wed Jun 13 11:23:55 2012 From: klappnase at web.de (Michael Lange) Date: Wed, 13 Jun 2012 11:23:55 +0200 Subject: [Tkinter-discuss] ttk.Spinbox missing? In-Reply-To: <20120613081210.74757ba0@dino> References: <20120613081210.74757ba0@dino> Message-ID: <20120613112355.4204d31f.klappnase@web.de> Thus spoketh Mark Summerfield unto us on Wed, 13 Jun 2012 08:12:10 +0100: > Hi, > > I have Python 3.2 with Tcl/Tk 8.5, but there doesn't seem to be a > ttk.Spinbox widget even though that widget is part of Tcl/Tk 8.5: > http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_spinbox.htm > > Why is that? Apparently no one has added it to the ttk wrapper module yet :( Obviously the spinbox was not there in earlier versions of ttk, that might explain this. Here, with Tk-8.5.8, I actually have a ttk_spinbox manpage installed, but: $ wish % ttk::entry .e .e % ttk::spinbox .s invalid command name "ttk::spinbox" % Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Totally illogical, there was no chance. -- Spock, "The Galileo Seven", stardate 2822.3 From list at qtrac.plus.com Wed Jun 13 12:41:03 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Wed, 13 Jun 2012 11:41:03 +0100 Subject: [Tkinter-discuss] ttk.Spinbox missing? In-Reply-To: <20120613112355.4204d31f.klappnase@web.de> References: <20120613081210.74757ba0@dino> <20120613112355.4204d31f.klappnase@web.de> Message-ID: <20120613114103.09d5abd4@dino> Hi Michael, On Wed, 13 Jun 2012 11:23:55 +0200 Michael Lange wrote: > Thus spoketh Mark Summerfield > unto us on Wed, 13 Jun 2012 08:12:10 +0100: > > > Hi, > > > > I have Python 3.2 with Tcl/Tk 8.5, but there doesn't seem to be a > > ttk.Spinbox widget even though that widget is part of Tcl/Tk 8.5: > > http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_spinbox.htm > > > > Why is that? > > Apparently no one has added it to the ttk wrapper module yet :( > Obviously the spinbox was not there in earlier versions of ttk, that > might explain this. Here, with Tk-8.5.8, I actually have a ttk_spinbox > manpage installed, but: > > $ wish > % ttk::entry .e > .e > % ttk::spinbox .s > invalid command name "ttk::spinbox" > % I just tried the above (and then pack .e and pack .s) and it worked. But I have 8.5.11. So maybe it'll get wrapped Python 3.4 (since I guess it is too late for 3.3?) -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Go" - ISBN 0321774639 http://www.qtrac.eu/gobook.html From klappnase at web.de Wed Jun 13 14:12:10 2012 From: klappnase at web.de (Michael Lange) Date: Wed, 13 Jun 2012 14:12:10 +0200 Subject: [Tkinter-discuss] ttk.Spinbox missing? In-Reply-To: <20120613114103.09d5abd4@dino> References: <20120613081210.74757ba0@dino> <20120613112355.4204d31f.klappnase@web.de> <20120613114103.09d5abd4@dino> Message-ID: <20120613141210.5acb2f28.klappnase@web.de> Hi Mark, Thus spoketh Mark Summerfield unto us on Wed, 13 Jun 2012 11:41:03 +0100: > > > > $ wish > > % ttk::entry .e > > .e > > % ttk::spinbox .s > > invalid command name "ttk::spinbox" > > % > > I just tried the above (and then pack .e and pack .s) and it worked. > > But I have 8.5.11. > > So maybe it'll get wrapped Python 3.4 (since I guess it is too late for > 3.3?) I don't know who currently maintains Tkinter and how much time they have to work on it, maybe it would help if someone wrote a patch. >From a quick glance I think the spinbox might not require any more code than the following snippet: ################################################################# import ttk class Spinbox(ttk.Entry): def __init__(self, master=None, **kw): ttk.Entry.__init__(self, master, "ttk::spinbox", **kw) def current(self, newindex=None): return self.tk.call(self._w, 'current', index) def set(self, value): return self.tk.call(self._w, 'set', value) ################################################################# Can you store this to a file spinbox.py and then import the spinbox widget from there and test if everything works? Maybe there still needs some tweaking to be done to make all configuration options work properly (as in ttk.Combobox). Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. There are some things worth dying for. -- Kirk, "Errand of Mercy", stardate 3201.7 From Cameron at phaseit.net Wed Jun 13 14:53:11 2012 From: Cameron at phaseit.net (Cameron Laird) Date: Wed, 13 Jun 2012 12:53:11 +0000 Subject: [Tkinter-discuss] Is it safe to use True/False for 1/0 in tkinter? In-Reply-To: <20120613111309.a8726215.klappnase@web.de> References: <20120611165855.1b8aa8b5@dino> <20120612140027.add7adfe.klappnase@web.de> <20120612121622.GA13487@lairds.us> <20120612190404.aef51811.klappnase@web.de> <20120613073604.1fcd78a5@dino> <20120613111309.a8726215.klappnase@web.de> Message-ID: <20120613125311.GA11755@lairds.us> On Wed, Jun 13, 2012 at 11:13:09AM +0200, Michael Lange wrote: . . . > Let's try another Tk method that wants a boolean: > > >>> root.tk_strictMotif(0.0) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 374, in tk_strictMotif > 'set', 'tk_strictMotif', boolean)) > TypeError: getboolean() argument 1 must be string, not float > >>> > > And when we look at what goes on behind the scenes: > > def tk_strictMotif(self, boolean=None): > """Set Tcl internal variable, whether the look and feel > should adhere to Motif. > > A parameter of 1 means adhere to Motif (e.g. no color > change if mouse passes over slider). > Returns the set value.""" > return self.tk.getboolean(self.tk.call( > 'set', 'tk_strictMotif', boolean)) > > we see that it's Tk itself which is not consistent, because > tk_strictMotif apparently returns the float where wm overrideredirect > does not. . . . Within Tk, tk_strictMotif definitely takes on values 0 and 1. I have no idea where the float emerges, nor the time now to look into the Tkinter interface. From list at qtrac.plus.com Wed Jun 13 14:55:36 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Wed, 13 Jun 2012 13:55:36 +0100 Subject: [Tkinter-discuss] ttk.Spinbox missing? In-Reply-To: <20120613141210.5acb2f28.klappnase@web.de> References: <20120613081210.74757ba0@dino> <20120613112355.4204d31f.klappnase@web.de> <20120613114103.09d5abd4@dino> <20120613141210.5acb2f28.klappnase@web.de> Message-ID: <20120613135536.5ecfd134@dino> Hi Michael, On Wed, 13 Jun 2012 14:12:10 +0200 Michael Lange wrote: [snip] > I don't know who currently maintains Tkinter and how much time they have > to work on it, maybe it would help if someone wrote a patch. > >From a quick glance I think the spinbox might not require any more code > than the following snippet: > > ################################################################# > import ttk > > class Spinbox(ttk.Entry): > > def __init__(self, master=None, **kw): > ttk.Entry.__init__(self, master, "ttk::spinbox", **kw) > > def current(self, newindex=None): > return self.tk.call(self._w, 'current', index) > > def set(self, value): > return self.tk.call(self._w, 'set', value) > ################################################################# > > Can you store this to a file spinbox.py and then import the spinbox > widget from there and test if everything works? Maybe there still needs > some tweaking to be done to make all configuration options work properly > (as in ttk.Combobox). I didn't check "everything", but I tried it and it worked. I respects the from and to values (when using the up and down arrows or the up and down arrow keys), but just like tk.Spinbox allows you to type in any old junk. -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Python 3" - ISBN 0321680561 http://www.qtrac.eu/py3book.html From dblank at cs.brynmawr.edu Wed Jun 13 15:34:57 2012 From: dblank at cs.brynmawr.edu (Douglas S. Blank) Date: Wed, 13 Jun 2012 09:34:57 -0400 Subject: [Tkinter-discuss] ttk.Spinbox missing? In-Reply-To: <20120613135536.5ecfd134@dino> References: <20120613081210.74757ba0@dino> <20120613112355.4204d31f.klappnase@web.de> <20120613114103.09d5abd4@dino> <20120613141210.5acb2f28.klappnase@web.de> <20120613135536.5ecfd134@dino> Message-ID: <4FD89701.3060604@cs.brynmawr.edu> On 06/13/2012 08:55 AM, Mark Summerfield wrote: > Hi Michael, > > On Wed, 13 Jun 2012 14:12:10 +0200 > Michael Lange wrote: > [snip] >> I don't know who currently maintains Tkinter and how much time they have >> to work on it, maybe it would help if someone wrote a patch. >> > From a quick glance I think the spinbox might not require any more code >> than the following snippet: >> >> ################################################################# >> import ttk >> >> class Spinbox(ttk.Entry): >> >> def __init__(self, master=None, **kw): >> ttk.Entry.__init__(self, master, "ttk::spinbox", **kw) >> >> def current(self, newindex=None): >> return self.tk.call(self._w, 'current', index) >> >> def set(self, value): >> return self.tk.call(self._w, 'set', value) >> ################################################################# >> >> Can you store this to a file spinbox.py and then import the spinbox >> widget from there and test if everything works? Maybe there still needs >> some tweaking to be done to make all configuration options work properly >> (as in ttk.Combobox). > > I didn't check "everything", but I tried it and it worked. I respects > the from and to values (when using the up and down arrows or the up and > down arrow keys), but just like tk.Spinbox allows you to type in any old > junk. > It does look like there is an error in current(): there is a newindex and index, but it doesn't look like index is defined, right? -Doug -- Douglas S. Blank, Associate Professor and Chair Department of Computer Science, Bryn Mawr College http://cs.brynmawr.edu/~dblank (610)526-6501 From klappnase at web.de Wed Jun 13 20:13:58 2012 From: klappnase at web.de (Michael Lange) Date: Wed, 13 Jun 2012 20:13:58 +0200 Subject: [Tkinter-discuss] Is it safe to use True/False for 1/0 in tkinter? In-Reply-To: <20120613125311.GA11755@lairds.us> References: <20120611165855.1b8aa8b5@dino> <20120612140027.add7adfe.klappnase@web.de> <20120612121622.GA13487@lairds.us> <20120612190404.aef51811.klappnase@web.de> <20120613073604.1fcd78a5@dino> <20120613111309.a8726215.klappnase@web.de> <20120613125311.GA11755@lairds.us> Message-ID: <20120613201358.a85ae35e.klappnase@web.de> Thus spoketh Cameron Laird unto us on Wed, 13 Jun 2012 12:53:11 +0000: > > > > we see that it's Tk itself which is not consistent, because > > tk_strictMotif apparently returns the float where wm overrideredirect > > does not. > . > . > . > Within Tk, tk_strictMotif definitely takes on values 0 > and 1. I have no idea where the float emerges, nor the > time now to look into the Tkinter interface. Seems like tk_strictMotif just returns what it gets as long as Tk somehow accepts it as boolean value: $ wish % set tk_strictMotif 0.0 0.0 % set tk_strictMotif false false % set tk_strictMotif on on % set tk_strictMotif 55 55 % set tk_strictMotif foo can't set "tk_strictMotif": expected boolean value but got "foo" % Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Another Armenia, Belgium ... the weak innocents who always seem to be located on a natural invasion route. -- Kirk, "Errand of Mercy", stardate 3198.4 From klappnase at web.de Wed Jun 13 20:17:33 2012 From: klappnase at web.de (Michael Lange) Date: Wed, 13 Jun 2012 20:17:33 +0200 Subject: [Tkinter-discuss] ttk.Spinbox missing? In-Reply-To: <4FD89701.3060604@cs.brynmawr.edu> References: <20120613081210.74757ba0@dino> <20120613112355.4204d31f.klappnase@web.de> <20120613114103.09d5abd4@dino> <20120613141210.5acb2f28.klappnase@web.de> <20120613135536.5ecfd134@dino> <4FD89701.3060604@cs.brynmawr.edu> Message-ID: <20120613201733.e9538813.klappnase@web.de> Thus spoketh "Douglas S. Blank" unto us on Wed, 13 Jun 2012 09:34:57 -0400: > > It does look like there is an error in current(): there is a newindex > and index, but it doesn't look like index is defined, right? Oops, clear case of a copy and paste accident, should be def current(self, newindex=None): return self.tk.call(self._w, 'current', newindex) of course ;) Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Insults are effective only where emotion is present. -- Spock, "Who Mourns for Adonais?" stardate 3468.1 From klappnase at web.de Wed Jun 13 20:43:24 2012 From: klappnase at web.de (Michael Lange) Date: Wed, 13 Jun 2012 20:43:24 +0200 Subject: [Tkinter-discuss] ttk.Spinbox missing? In-Reply-To: <20120613135536.5ecfd134@dino> References: <20120613081210.74757ba0@dino> <20120613112355.4204d31f.klappnase@web.de> <20120613114103.09d5abd4@dino> <20120613141210.5acb2f28.klappnase@web.de> <20120613135536.5ecfd134@dino> Message-ID: <20120613204324.07a461c3.klappnase@web.de> Hi, Thus spoketh Mark Summerfield unto us on Wed, 13 Jun 2012 13:55:36 +0100: > > I didn't check "everything", but I tried it and it worked. I respects > the from and to values (when using the up and down arrows or the up and > down arrow keys), but just like tk.Spinbox allows you to type in any old > junk. Sure, if you want only a certain set of values to be legal, you need to deal with validatecommand and friends, see http://www.tcl.tk/man/tcl8.4/TkCmd/spinbox.htm#M26 Validation is not exactly trivial in Python though, because you will have to manage percent substitutions yourself, as in this little example of a spinbox that only accepts float values between -10.0 and 100.0: ######################################## from Tkinter import * root = Tk() var = StringVar() var.set('0') s = Spinbox(root, from_=-10.0, to=100.0, increment=1, textvariable=var, validate='all', format='%0.1f') s.pack() def validate(old, new): if new == '': res = True else: try: x = float(new) if float(s['from']) <= x <= float(s['to']): res = True else: res = False except ValueError: res = False return res vcmd = (s.register(validate), '%s', '%P') s.config(vcmd=vcmd, invcmd=s.bell) root.mainloop() ######################################## Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. There is a multi-legged creature crawling on your shoulder. -- Spock, "A Taste of Armageddon", stardate 3193.9 From list at qtrac.plus.com Thu Jun 14 08:54:25 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Thu, 14 Jun 2012 07:54:25 +0100 Subject: [Tkinter-discuss] ttk.Spinbox missing? In-Reply-To: <20120613204324.07a461c3.klappnase@web.de> References: <20120613081210.74757ba0@dino> <20120613112355.4204d31f.klappnase@web.de> <20120613114103.09d5abd4@dino> <20120613141210.5acb2f28.klappnase@web.de> <20120613135536.5ecfd134@dino> <20120613204324.07a461c3.klappnase@web.de> Message-ID: <20120614075425.4f2d87dc@dino> Hi Michael, On Wed, 13 Jun 2012 20:43:24 +0200 Michael Lange wrote: > Hi, > > Thus spoketh Mark Summerfield > unto us on Wed, 13 Jun 2012 13:55:36 +0100: > > > > > I didn't check "everything", but I tried it and it worked. I respects > > the from and to values (when using the up and down arrows or the up and > > down arrow keys), but just like tk.Spinbox allows you to type in any > > old junk. > > Sure, if you want only a certain set of values to be legal, you need to > deal with validatecommand and friends, see > > http://www.tcl.tk/man/tcl8.4/TkCmd/spinbox.htm#M26 > > Validation is not exactly trivial in Python though, because you will > have to manage percent substitutions yourself, as in this little example > of a spinbox that only accepts float values between -10.0 and 100.0: > > ######################################## > from Tkinter import * > > root = Tk() > var = StringVar() > var.set('0') > s = Spinbox(root, from_=-10.0, to=100.0, increment=1, textvariable=var, > validate='all', format='%0.1f') > s.pack() > > def validate(old, new): > if new == '': > res = True > else: > try: > x = float(new) > if float(s['from']) <= x <= float(s['to']): > res = True > else: > res = False > except ValueError: > res = False > return res > > vcmd = (s.register(validate), '%s', '%P') > s.config(vcmd=vcmd, invcmd=s.bell) > > root.mainloop() > ######################################## Wow! I hadn't known about the register() method. AFAIK it isn't in the Tcl/Tk or Tkinter documentation. (Which makes me wonder what else is missing?) Incidentally, in the example above, the '%s' and old value are redundant. Thanks:-) -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Go" - ISBN 0321774639 http://www.qtrac.eu/gobook.html From klappnase at web.de Thu Jun 14 12:30:59 2012 From: klappnase at web.de (Michael Lange) Date: Thu, 14 Jun 2012 12:30:59 +0200 Subject: [Tkinter-discuss] ttk.Spinbox missing? In-Reply-To: <20120614075425.4f2d87dc@dino> References: <20120613081210.74757ba0@dino> <20120613112355.4204d31f.klappnase@web.de> <20120613114103.09d5abd4@dino> <20120613141210.5acb2f28.klappnase@web.de> <20120613135536.5ecfd134@dino> <20120613204324.07a461c3.klappnase@web.de> <20120614075425.4f2d87dc@dino> Message-ID: <20120614123059.77d2db29.klappnase@web.de> Thus spoketh Mark Summerfield unto us on Thu, 14 Jun 2012 07:54:25 +0100: > Wow! I hadn't known about the register() method. > AFAIK it isn't in the Tcl/Tk or Tkinter documentation. > (Which makes me wonder what else is missing?) > > Incidentally, in the example above, the '%s' and old value are > redundant. > You're right, I copy'n'pasted that code again, from a more complex example; in the original code I use the "old" value as a kind of "backup" that is used in situations when get() is called while the spinbox is empty, the old value is then used to make sure get() always returns something useful. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. A father doesn't destroy his children. -- Lt. Carolyn Palamas, "Who Mourns for Adonais?", stardate 3468.1. From list at qtrac.plus.com Fri Jun 15 13:07:38 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Fri, 15 Jun 2012 12:07:38 +0100 Subject: [Tkinter-discuss] a couple of mac menu problems Message-ID: <20120615120738.0eedbd9d@dino> Hi, I'm trying to develop a cross-platform Tkinter app. Here's a bit of code used to create the Help menu: if MAC: self.master.createcommand("tkAboutDialog", self.about_action) self.master.createcommand("::tk::mac::ShowHelp", self.help_action) helpMenu = tk.Menu(self.menubar, name="help") helpMenu.add_command(label="Help", underline=0, command=self.help_action) if not MAC: helpMenu.add_command(label="About", underline=0, command=self.about_action) self.menubar.add_cascade(label="Help", underline=0, menu=helpMenu) I end up with these menus: ActivePython3.2 About ActivePython3.2 # correctly invokes my about action ... Help Search # some apple-specific thing that just appears ActivePython3.2 Help # invokes my help action Help # invokes my help action Problems: (1) I don't know how to rename the "ActivePython3.2" menu to "My App". (2) I don't know how to rename the "About ActivePython3.2" menu option to "About" or "About My App". (3) I don't know how to eliminate the "ActivePython3.2 Help" menu option. If I don't do helpMenu.add_command() on the Mac that menu has no items ('cos the About is in the ActivePython3.2 menu) and so the Help menu doesn't appear at all. Can anyone advise? Thanks! -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Advanced Qt Programming" - ISBN 0321635906 http://www.qtrac.eu/aqpbook.html From kw at codebykevin.com Fri Jun 15 15:45:58 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 15 Jun 2012 09:45:58 -0400 Subject: [Tkinter-discuss] a couple of mac menu problems In-Reply-To: <20120615120738.0eedbd9d@dino> References: <20120615120738.0eedbd9d@dino> Message-ID: <4FDB3C96.9070003@codebykevin.com> Hi Mark, Please see my answers below: > Here's a bit of code used to create the Help menu: > > if MAC: > self.master.createcommand("tkAboutDialog", self.about_action) > self.master.createcommand("::tk::mac::ShowHelp", > self.help_action) > helpMenu = tk.Menu(self.menubar, name="help") > helpMenu.add_command(label="Help", underline=0, > command=self.help_action) > if not MAC: > helpMenu.add_command(label="About", underline=0, > command=self.about_action) > self.menubar.add_cascade(label="Help", underline=0, > menu=helpMenu) There's some magic in the Tk-Cocoa help menu--if you define the tk::mac::showHelp command and map it to your function that calls user help, you don't need to add a separate entry for help. (There's already an entry hard-coded for help, along with the search field.) So the helpMenu.add_Command(label="Help")... stuff is redundant. > I end up with these menus: > > ActivePython3.2 > About ActivePython3.2 # correctly invokes my about action If you're just running the app from Python and not wrapping it with a tool such as py2app, this is the expected behavior. The "about" menu picks up the name of the executable from its info.plist file, which in this case is Python. > > Help > Search # some apple-specific thing that just appears > ActivePython3.2 Help # invokes my help action > Help # invokes my help action > > Problems: > > (1) I don't know how to rename the "ActivePython3.2" menu to "My App". > (2) I don't know how to rename the "About ActivePython3.2" menu option > to "About" or "About My App". See above--you need to wrap this as a standalone app using py2app or cx_freeze. > (3) I don't know how to eliminate the "ActivePython3.2 Help" menu option. > If I don't do helpMenu.add_command() on the Mac that menu has no > items ('cos the About is in the ActivePython3.2 menu) and so the > Help menu doesn't appear at all. If you don't add any items to the help menu but just define it, I would expect to see an entry called "ActivePython 3.2 Help" that calls up a dialog which says, "Help isn't available for ActivePython 3.2." This is how I set up my help menu is one of my Python apps: self.createcommand('::tk::mac::ShowHelp', self.runHelp) self.helpmenu = Menu(self.mb, name='_help') self.mb.add_cascade(label='Help', menu=self.helpmenu) self.helpmenu.add_command(label='Phynchronicity Help', command=self.runHelp) self.helpmenu.add_command(label='Contact Code by Kevin', command=self.getHelp) self.helpmenu.add_command(label='Web Site', command=self.getWebSite) self.helpmenu.add_command(label='User Forum', command=self.getUserForum) self.helpmenu.add_command(label='Newsletter', command=self.getNewsletter) Hope this helps, Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From raycores at gmail.com Fri Jun 15 20:06:38 2012 From: raycores at gmail.com (Lynn Oliver) Date: Fri, 15 Jun 2012 11:06:38 -0700 Subject: [Tkinter-discuss] a couple of mac menu problems In-Reply-To: <4FDB3C96.9070003@codebykevin.com> References: <20120615120738.0eedbd9d@dino> <4FDB3C96.9070003@codebykevin.com> Message-ID: <0B576DCF-F725-4546-AF63-6905EE7ADFB1@gmail.com> Along the same lines, I managed to get application/preferences to work on the Mac, but while application/about shows the name of my Python app (built with pyinstaller), it displays the 'Tcl & Tk' dialog. The TkDocs-TK Tutorial on menus shows this as a TODO item (http://www.tkdocs.com/tutorial/menus.html). While I was able to figure out the preferences menu by looking at the idlelib sources, I couldn't get the application/about menu to work. Any suggestions? Lynn On Jun 15, 2012, at 6:45 AM, Kevin Walzer wrote: > Hi Mark, > > Please see my answers below: > > >> Here's a bit of code used to create the Help menu: >> >> if MAC: >> self.master.createcommand("tkAboutDialog", self.about_action) >> self.master.createcommand("::tk::mac::ShowHelp", >> self.help_action) >> helpMenu = tk.Menu(self.menubar, name="help") >> helpMenu.add_command(label="Help", underline=0, >> command=self.help_action) >> if not MAC: >> helpMenu.add_command(label="About", underline=0, >> command=self.about_action) >> self.menubar.add_cascade(label="Help", underline=0, >> menu=helpMenu) > > There's some magic in the Tk-Cocoa help menu--if you define the tk::mac::showHelp command and map it to your function that calls user help, you don't need to add a separate entry for help. (There's already an entry hard-coded for help, along with the search field.) So the helpMenu.add_Command(label="Help")... stuff is redundant. > >> I end up with these menus: >> >> ActivePython3.2 >> About ActivePython3.2 # correctly invokes my about action > > If you're just running the app from Python and not wrapping it with a tool such as py2app, this is the expected behavior. The "about" menu picks up the name of the executable from its info.plist file, which in this case is Python. > >> >> Help >> Search # some apple-specific thing that just appears >> ActivePython3.2 Help # invokes my help action >> Help # invokes my help action > >> >> Problems: >> >> (1) I don't know how to rename the "ActivePython3.2" menu to "My App". >> (2) I don't know how to rename the "About ActivePython3.2" menu option >> to "About" or "About My App". > > See above--you need to wrap this as a standalone app using py2app or cx_freeze. > >> (3) I don't know how to eliminate the "ActivePython3.2 Help" menu option. >> If I don't do helpMenu.add_command() on the Mac that menu has no >> items ('cos the About is in the ActivePython3.2 menu) and so the >> Help menu doesn't appear at all. > > If you don't add any items to the help menu but just define it, I would expect to see an entry called "ActivePython 3.2 Help" that calls up a dialog which says, "Help isn't available for ActivePython 3.2." > > This is how I set up my help menu is one of my Python apps: > > self.createcommand('::tk::mac::ShowHelp', self.runHelp) > > self.helpmenu = Menu(self.mb, name='_help') > self.mb.add_cascade(label='Help', menu=self.helpmenu) > self.helpmenu.add_command(label='Phynchronicity Help', command=self.runHelp) > self.helpmenu.add_command(label='Contact Code by Kevin', command=self.getHelp) > self.helpmenu.add_command(label='Web Site', command=self.getWebSite) > self.helpmenu.add_command(label='User Forum', command=self.getUserForum) > self.helpmenu.add_command(label='Newsletter', command=self.getNewsletter) > > Hope this helps, > Kevin > > -- > Kevin Walzer > Code by Kevin > http://www.codebykevin.com > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss From kw at codebykevin.com Fri Jun 15 20:32:47 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 15 Jun 2012 14:32:47 -0400 Subject: [Tkinter-discuss] a couple of mac menu problems In-Reply-To: <0B576DCF-F725-4546-AF63-6905EE7ADFB1@gmail.com> References: <20120615120738.0eedbd9d@dino> <4FDB3C96.9070003@codebykevin.com> <0B576DCF-F725-4546-AF63-6905EE7ADFB1@gmail.com> Message-ID: <0B0314E7-28CF-4145-A69D-F483C0F4D0E7@codebykevin.com> What version of OS X? Sent from my iPhone On Jun 15, 2012, at 2:06 PM, Lynn Oliver wrote: > Along the same lines, I managed to get application/preferences to work on the Mac, but while application/about shows the name of my Python app (built with pyinstaller), it displays the 'Tcl & Tk' dialog. > > The TkDocs-TK Tutorial on menus shows this as a TODO item (http://www.tkdocs.com/tutorial/menus.html). While I was able to figure out the preferences menu by looking at the idlelib sources, I couldn't get the application/about menu to work. > > Any suggestions? > > Lynn > On Jun 15, 2012, at 6:45 AM, Kevin Walzer wrote: > >> Hi Mark, >> >> Please see my answers below: >> >> >>> Here's a bit of code used to create the Help menu: >>> >>> if MAC: >>> self.master.createcommand("tkAboutDialog", self.about_action) >>> self.master.createcommand("::tk::mac::ShowHelp", >>> self.help_action) >>> helpMenu = tk.Menu(self.menubar, name="help") >>> helpMenu.add_command(label="Help", underline=0, >>> command=self.help_action) >>> if not MAC: >>> helpMenu.add_command(label="About", underline=0, >>> command=self.about_action) >>> self.menubar.add_cascade(label="Help", underline=0, >>> menu=helpMenu) >> >> There's some magic in the Tk-Cocoa help menu--if you define the tk::mac::showHelp command and map it to your function that calls user help, you don't need to add a separate entry for help. (There's already an entry hard-coded for help, along with the search field.) So the helpMenu.add_Command(label="Help")... stuff is redundant. >> >>> I end up with these menus: >>> >>> ActivePython3.2 >>> About ActivePython3.2 # correctly invokes my about action >> >> If you're just running the app from Python and not wrapping it with a tool such as py2app, this is the expected behavior. The "about" menu picks up the name of the executable from its info.plist file, which in this case is Python. >> >>> >>> Help >>> Search # some apple-specific thing that just appears >>> ActivePython3.2 Help # invokes my help action >>> Help # invokes my help action >> >>> >>> Problems: >>> >>> (1) I don't know how to rename the "ActivePython3.2" menu to "My App". >>> (2) I don't know how to rename the "About ActivePython3.2" menu option >>> to "About" or "About My App". >> >> See above--you need to wrap this as a standalone app using py2app or cx_freeze. >> >>> (3) I don't know how to eliminate the "ActivePython3.2 Help" menu option. >>> If I don't do helpMenu.add_command() on the Mac that menu has no >>> items ('cos the About is in the ActivePython3.2 menu) and so the >>> Help menu doesn't appear at all. >> >> If you don't add any items to the help menu but just define it, I would expect to see an entry called "ActivePython 3.2 Help" that calls up a dialog which says, "Help isn't available for ActivePython 3.2." >> >> This is how I set up my help menu is one of my Python apps: >> >> self.createcommand('::tk::mac::ShowHelp', self.runHelp) >> >> self.helpmenu = Menu(self.mb, name='_help') >> self.mb.add_cascade(label='Help', menu=self.helpmenu) >> self.helpmenu.add_command(label='Phynchronicity Help', command=self.runHelp) >> self.helpmenu.add_command(label='Contact Code by Kevin', command=self.getHelp) >> self.helpmenu.add_command(label='Web Site', command=self.getWebSite) >> self.helpmenu.add_command(label='User Forum', command=self.getUserForum) >> self.helpmenu.add_command(label='Newsletter', command=self.getNewsletter) >> >> Hope this helps, >> Kevin >> >> -- >> Kevin Walzer >> Code by Kevin >> http://www.codebykevin.com >> _______________________________________________ >> Tkinter-discuss mailing list >> Tkinter-discuss at python.org >> http://mail.python.org/mailman/listinfo/tkinter-discuss > From raycores at gmail.com Fri Jun 15 20:53:52 2012 From: raycores at gmail.com (Lynn Oliver) Date: Fri, 15 Jun 2012 11:53:52 -0700 Subject: [Tkinter-discuss] a couple of mac menu problems In-Reply-To: <0B0314E7-28CF-4145-A69D-F483C0F4D0E7@codebykevin.com> References: <20120615120738.0eedbd9d@dino> <4FDB3C96.9070003@codebykevin.com> <0B576DCF-F725-4546-AF63-6905EE7ADFB1@gmail.com> <0B0314E7-28CF-4145-A69D-F483C0F4D0E7@codebykevin.com> Message-ID: <0FB8F70A-E6B8-4744-9BD0-8C7D4676F330@gmail.com> I'm testing on 10.7.4, but it needs to work on 10.6 as well. On Jun 15, 2012, at 11:32 AM, Kevin Walzer wrote: > What version of OS X? > > Sent from my iPhone > > On Jun 15, 2012, at 2:06 PM, Lynn Oliver wrote: > >> Along the same lines, I managed to get application/preferences to work on the Mac, but while application/about shows the name of my Python app (built with pyinstaller), it displays the 'Tcl & Tk' dialog. >> >> The TkDocs-TK Tutorial on menus shows this as a TODO item (http://www.tkdocs.com/tutorial/menus.html). While I was able to figure out the preferences menu by looking at the idlelib sources, I couldn't get the application/about menu to work. >> >> Any suggestions? >> >> Lynn >> On Jun 15, 2012, at 6:45 AM, Kevin Walzer wrote: >> >>> Hi Mark, >>> >>> Please see my answers below: >>> >>> >>>> Here's a bit of code used to create the Help menu: >>>> >>>> if MAC: >>>> self.master.createcommand("tkAboutDialog", self.about_action) >>>> self.master.createcommand("::tk::mac::ShowHelp", >>>> self.help_action) >>>> helpMenu = tk.Menu(self.menubar, name="help") >>>> helpMenu.add_command(label="Help", underline=0, >>>> command=self.help_action) >>>> if not MAC: >>>> helpMenu.add_command(label="About", underline=0, >>>> command=self.about_action) >>>> self.menubar.add_cascade(label="Help", underline=0, >>>> menu=helpMenu) >>> >>> There's some magic in the Tk-Cocoa help menu--if you define the tk::mac::showHelp command and map it to your function that calls user help, you don't need to add a separate entry for help. (There's already an entry hard-coded for help, along with the search field.) So the helpMenu.add_Command(label="Help")... stuff is redundant. >>> >>>> I end up with these menus: >>>> >>>> ActivePython3.2 >>>> About ActivePython3.2 # correctly invokes my about action >>> >>> If you're just running the app from Python and not wrapping it with a tool such as py2app, this is the expected behavior. The "about" menu picks up the name of the executable from its info.plist file, which in this case is Python. >>> >>>> >>>> Help >>>> Search # some apple-specific thing that just appears >>>> ActivePython3.2 Help # invokes my help action >>>> Help # invokes my help action >>> >>>> >>>> Problems: >>>> >>>> (1) I don't know how to rename the "ActivePython3.2" menu to "My App". >>>> (2) I don't know how to rename the "About ActivePython3.2" menu option >>>> to "About" or "About My App". >>> >>> See above--you need to wrap this as a standalone app using py2app or cx_freeze. >>> >>>> (3) I don't know how to eliminate the "ActivePython3.2 Help" menu option. >>>> If I don't do helpMenu.add_command() on the Mac that menu has no >>>> items ('cos the About is in the ActivePython3.2 menu) and so the >>>> Help menu doesn't appear at all. >>> >>> If you don't add any items to the help menu but just define it, I would expect to see an entry called "ActivePython 3.2 Help" that calls up a dialog which says, "Help isn't available for ActivePython 3.2." >>> >>> This is how I set up my help menu is one of my Python apps: >>> >>> self.createcommand('::tk::mac::ShowHelp', self.runHelp) >>> >>> self.helpmenu = Menu(self.mb, name='_help') >>> self.mb.add_cascade(label='Help', menu=self.helpmenu) >>> self.helpmenu.add_command(label='Phynchronicity Help', command=self.runHelp) >>> self.helpmenu.add_command(label='Contact Code by Kevin', command=self.getHelp) >>> self.helpmenu.add_command(label='Web Site', command=self.getWebSite) >>> self.helpmenu.add_command(label='User Forum', command=self.getUserForum) >>> self.helpmenu.add_command(label='Newsletter', command=self.getNewsletter) >>> >>> Hope this helps, >>> Kevin >>> >>> -- >>> Kevin Walzer >>> Code by Kevin >>> http://www.codebykevin.com >>> _______________________________________________ >>> Tkinter-discuss mailing list >>> Tkinter-discuss at python.org >>> http://mail.python.org/mailman/listinfo/tkinter-discuss >> From kw at codebykevin.com Fri Jun 15 22:59:04 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 15 Jun 2012 16:59:04 -0400 Subject: [Tkinter-discuss] a couple of mac menu problems In-Reply-To: <0FB8F70A-E6B8-4744-9BD0-8C7D4676F330@gmail.com> References: <20120615120738.0eedbd9d@dino> <4FDB3C96.9070003@codebykevin.com> <0B576DCF-F725-4546-AF63-6905EE7ADFB1@gmail.com> <0B0314E7-28CF-4145-A69D-F483C0F4D0E7@codebykevin.com> <0FB8F70A-E6B8-4744-9BD0-8C7D4676F330@gmail.com> Message-ID: <4FDBA218.2050704@codebykevin.com> On 6/15/12 2:53 PM, Lynn Oliver wrote: > I'm testing on 10.7.4, but it needs to work on 10.6 as well. >>> Along the same lines, I managed to get application/preferences to work on the Mac, but while application/about shows the name of my Python app (built with pyinstaller), it displays the 'Tcl& Tk' dialog. What does "CFBundleName" in your info.plist file show? I've seen this bug on the system version of Tcl/Tk installed with Snow Leopard, but not more recently. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From kw at codebykevin.com Sat Jun 16 02:38:24 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 15 Jun 2012 20:38:24 -0400 Subject: [Tkinter-discuss] a couple of mac menu problems In-Reply-To: <102C1807-3A29-4D86-A516-1D0B03CD330D@gmail.com> References: <20120615120738.0eedbd9d@dino> <4FDB3C96.9070003@codebykevin.com> <0B576DCF-F725-4546-AF63-6905EE7ADFB1@gmail.com> <0B0314E7-28CF-4145-A69D-F483C0F4D0E7@codebykevin.com> <0FB8F70A-E6B8-4744-9BD0-8C7D4676F330@gmail.com> <4FDBA218.2050704@codebykevin.com> <164B29AA-2FCA-4555-9B9B-6BF6EDD5FF45@codebykevin.com> <102C1807-3A29-4D86-A516-1D0B03CD330D@gmail.com> Message-ID: <4FDBD580.5060004@codebykevin.com> On 6/15/12 8:05 PM, Lynn Oliver wrote: > CDBundleName is not in the info.plist file; "Bundle name" is the name of the app. > On Jun 15, 2012, at 4:13 PM, Kevin Walzer wrote: > >> Myapp.app/Contents/info.plist Can you attach a copy of your info.plist file, or post a link to the app so I can download it and take a look? (I'm curious to see what a pyinstaller app looks like, anyway.) --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From kw at codebykevin.com Sat Jun 16 03:17:23 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 15 Jun 2012 21:17:23 -0400 Subject: [Tkinter-discuss] a couple of mac menu problems In-Reply-To: <0B576DCF-F725-4546-AF63-6905EE7ADFB1@gmail.com> References: <20120615120738.0eedbd9d@dino> <4FDB3C96.9070003@codebykevin.com> <0B576DCF-F725-4546-AF63-6905EE7ADFB1@gmail.com> Message-ID: <4FDBDEA3.1030202@codebykevin.com> On 6/15/12 2:06 PM, Lynn Oliver wrote: > While I was able to figure out the preferences menu by looking at the idlelib sources, I couldn't get the application/about menu to work. Here's how I get the correct application dialog in the 'about myapp" menu: self.createcommand('tkAboutDialog', self.aboutProgram) #dialog for 'about program' def aboutProgram(self): self.tk.call('tk::mac::standardAboutPanel') (You can substitute any Python bits here that you want--the key is to map the 'tkAboutDialog' command to some kind of Python function or method.) -- Kevin Walzer Code by Kevin http://www.codebykevin.com From list at qtrac.plus.com Mon Jun 18 08:46:33 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Mon, 18 Jun 2012 07:46:33 +0100 Subject: [Tkinter-discuss] is it possible to use a local tcl/tk with a local python? Message-ID: <20120618074633.68b83d12@dino> Hi, Right now I have several local pythons so that I can test against multiple versions, e.g., ~/opt/python31 ~/opt/python32 ~/opt/python33 But all of these use the system-wide Tcl/Tck (8.5.11) in /usr/lib. What I'd really like to do is have: ~/opt/python31tk85 ~/opt/python32tk85 ~/opt/python33tk85 ~/opt/python31tk86 ~/opt/python32tk86 ~/opt/python33tk86 where these are built with one of these: ~/opt/tcltk85 ~/opt/tcltk86 But I can't figure out how to tell Python's configure to use a local Tcl/Tk. Can anyone advise me? Thanks! -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Advanced Qt Programming" - ISBN 0321635906 http://www.qtrac.eu/aqpbook.html From list at qtrac.plus.com Mon Jun 18 10:23:06 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Mon, 18 Jun 2012 09:23:06 +0100 Subject: [Tkinter-discuss] a couple of mac menu problems In-Reply-To: <4FDB3C96.9070003@codebykevin.com> References: <20120615120738.0eedbd9d@dino> <4FDB3C96.9070003@codebykevin.com> Message-ID: <20120618092306.4fe1428c@dino> Hi Kevin, On Fri, 15 Jun 2012 09:45:58 -0400 Kevin Walzer wrote: > Hi Mark, [snip] > This is how I set up my help menu is one of my Python apps: > > self.createcommand('::tk::mac::ShowHelp', self.runHelp) > > self.helpmenu = Menu(self.mb, name='_help') > self.mb.add_cascade(label='Help', menu=self.helpmenu) > self.helpmenu.add_command(label='Phynchronicity Help', > command=self.runHelp) > self.helpmenu.add_command(label='Contact Code by Kevin', > command=self.getHelp) > self.helpmenu.add_command(label='Web Site', > command=self.getWebSite) > self.helpmenu.add_command(label='User Forum', > command=self.getUserForum) > self.helpmenu.add_command(label='Newsletter', > command=self.getNewsletter) > > Hope this helps, Yes, it was very helpful -- thanks! -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Python 3" - ISBN 0321680561 http://www.qtrac.eu/py3book.html From klappnase at web.de Mon Jun 18 11:04:23 2012 From: klappnase at web.de (Michael Lange) Date: Mon, 18 Jun 2012 11:04:23 +0200 Subject: [Tkinter-discuss] is it possible to use a local tcl/tk with a local python? In-Reply-To: <20120618074633.68b83d12@dino> References: <20120618074633.68b83d12@dino> Message-ID: <20120618110423.b213f6c6.klappnase@web.de> Thus spoketh Mark Summerfield unto us on Mon, 18 Jun 2012 07:46:33 +0100: > What I'd really like to do is have: > > ~/opt/python31tk85 > ~/opt/python32tk85 > ~/opt/python33tk85 > > ~/opt/python31tk86 > ~/opt/python32tk86 > ~/opt/python33tk86 > > where these are built with one of these: > > ~/opt/tcltk85 > ~/opt/tcltk86 > > But I can't figure out how to tell Python's configure to use a local > Tcl/Tk. I remember that I have been struggling with the same problem some time ago and never found a really satisfying solution. IIRC what worked best here was to temporarily remove the system default tcl/tk development packages and then do something like $ export LD_LIBRARY_PATH=~/opt/tcltk85 before running ./configure . Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. ... The prejudices people feel about each other disappear when they get to know each other. -- Kirk, "Elaan of Troyius", stardate 4372.5 From nad at acm.org Mon Jun 18 18:57:49 2012 From: nad at acm.org (Ned Deily) Date: Mon, 18 Jun 2012 09:57:49 -0700 Subject: [Tkinter-discuss] is it possible to use a local tcl/tk with a local python? References: <20120618074633.68b83d12@dino> Message-ID: In article <20120618074633.68b83d12 at dino>, Mark Summerfield wrote: > But I can't figure out how to tell Python's configure to use a local > Tcl/Tk. > > Can anyone advise me? http://permalink.gmane.org/gmane.comp.python.general/711390 -- Ned Deily, nad at acm.org From list at qtrac.plus.com Wed Jun 20 10:55:00 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Wed, 20 Jun 2012 09:55:00 +0100 Subject: [Tkinter-discuss] Focus for first key press Message-ID: <20120620095500.5bbf203f@dino> Hi, I have a couple of Tkinter applications and what I've noticed is that if I do Alt+F as soon as they start (i.e., for Alt+F,N for New or Alt+F,O for Open), the keypress is ignored! It works fine the second and all subsequent times. I've tried calling focus() on the invisible root window & on the topmost visible window, but neither has any effect. Can anyone tell me a solution? Thanks! -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Python 3" - ISBN 0321680561 http://www.qtrac.eu/py3book.html From klappnase at web.de Wed Jun 20 18:33:58 2012 From: klappnase at web.de (Michael Lange) Date: Wed, 20 Jun 2012 18:33:58 +0200 Subject: [Tkinter-discuss] Focus for first key press In-Reply-To: <20120620095500.5bbf203f@dino> References: <20120620095500.5bbf203f@dino> Message-ID: <20120620183358.e3bf2fa0.klappnase@web.de> Hi Mark, Thus spoketh Mark Summerfield unto us on Wed, 20 Jun 2012 09:55:00 +0100: > Hi, > > I have a couple of Tkinter applications and what I've noticed is that if > I do Alt+F as soon as they start (i.e., for Alt+F,N for New or Alt+F,O > for Open), the keypress is ignored! It works fine the second and all > subsequent times. > > I've tried calling focus() on the invisible root window & on the topmost > visible window, but neither has any effect. > > Can anyone tell me a solution? I am not sure what you are actually trying to do, could you please post a simple example that shows the problem? Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. The people of Gideon have always believed that life is sacred. That the love of life is the greatest gift ... We are incapable of destroying or interfering with the creation of that which we love so deeply -- life in every form from fetus to developed being. -- Hodin of Gideon, "The Mark of Gideon", stardate 5423.4 From list at qtrac.plus.com Thu Jun 21 09:03:55 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Thu, 21 Jun 2012 08:03:55 +0100 Subject: [Tkinter-discuss] Focus for first key press In-Reply-To: <20120620183358.e3bf2fa0.klappnase@web.de> References: <20120620095500.5bbf203f@dino> <20120620183358.e3bf2fa0.klappnase@web.de> Message-ID: <20120621080355.005192ed@dino> Hi Michael, On Wed, 20 Jun 2012 18:33:58 +0200 Michael Lange wrote: > Hi Mark, > > Thus spoketh Mark Summerfield > unto us on Wed, 20 Jun 2012 09:55:00 +0100: > > > Hi, > > > > I have a couple of Tkinter applications and what I've noticed is that > > if I do Alt+F as soon as they start (i.e., for Alt+F,N for New or > > Alt+F,O for Open), the keypress is ignored! It works fine the second > > and all subsequent times. > > > > I've tried calling focus() on the invisible root window & on the > > topmost visible window, but neither has any effect. > > > > Can anyone tell me a solution? > > I am not sure what you are actually trying to do, could you please post a > simple example that shows the problem? Below is an example. If I do $ python3 hello.pyw and then type Alt+F, the File menu does _not_ pop up. If I then type Alt+F a second (or subsequent) time it does. It seems that Tkinter is ignoring the *very first keypress*. If I press any key (e.g., Space, or x) and _then_ Alt+F, the File menu pops up as it should. ############################################################ import tkinter as tk import tkinter.ttk as ttk class Window(ttk.Frame): def __init__(self, master=None): super().__init__(master) self.menubar = tk.Menu(self.master) self.master.config(menu=self.menubar) fileMenu = tk.Menu(self.menubar, name="apple") fileMenu.add_command(label="Quit", underline=0, command=self.master.destroy) self.menubar.add_cascade(label="File", underline=0, menu=fileMenu) helloLabel = ttk.Label(self, text="Hello") helloLabel.pack() self.pack() self.master.minsize(100, 100) window = Window() window.master.title("Hello") window.master.mainloop() ############################################################ Thanks! -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Go" - ISBN 0321774639 http://www.qtrac.eu/gobook.html From klappnase at web.de Thu Jun 21 10:52:30 2012 From: klappnase at web.de (Michael Lange) Date: Thu, 21 Jun 2012 10:52:30 +0200 Subject: [Tkinter-discuss] Focus for first key press In-Reply-To: <20120621080355.005192ed@dino> References: <20120620095500.5bbf203f@dino> <20120620183358.e3bf2fa0.klappnase@web.de> <20120621080355.005192ed@dino> Message-ID: <20120621105230.7a270e6c.klappnase@web.de> Hi Mark, Thus spoketh Mark Summerfield unto us on Thu, 21 Jun 2012 08:03:55 +0100: > Below is an example. If I do > > $ python3 hello.pyw > > and then type Alt+F, the File menu does _not_ pop up. If I then type > Alt+F a second (or subsequent) time it does. > > It seems that Tkinter is ignoring the *very first keypress*. If I press > any key (e.g., Space, or x) and _then_ Alt+F, the File menu pops up as > it should. I cannot reproduce this behavior, here (debian squeeze) the example works as expected, so the problem appears to be platform specific. Does this happen with "normal" bindings created through bind(), too (which might point to some window manager issue) or with menu shortcuts only (which might point to the tk magic that handles these behind the scenes), and what is the exact platform ? Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Not one hundred percent efficient, of course ... but nothing ever is. -- Kirk, "Metamorphosis", stardate 3219.8 From list at qtrac.plus.com Thu Jun 21 11:44:14 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Thu, 21 Jun 2012 10:44:14 +0100 Subject: [Tkinter-discuss] Focus for first key press In-Reply-To: <20120621105230.7a270e6c.klappnase@web.de> References: <20120620095500.5bbf203f@dino> <20120620183358.e3bf2fa0.klappnase@web.de> <20120621080355.005192ed@dino> <20120621105230.7a270e6c.klappnase@web.de> Message-ID: <20120621104414.66e6148f@dino> On Thu, 21 Jun 2012 10:52:30 +0200 Michael Lange wrote: > Hi Mark, > > Thus spoketh Mark Summerfield > unto us on Thu, 21 Jun 2012 08:03:55 +0100: > > > Below is an example. If I do > > > > $ python3 hello.pyw > > > > and then type Alt+F, the File menu does _not_ pop up. If I then type > > Alt+F a second (or subsequent) time it does. > > > > It seems that Tkinter is ignoring the *very first keypress*. If I press > > any key (e.g., Space, or x) and _then_ Alt+F, the File menu pops up as > > it should. > > I cannot reproduce this behavior, here (debian squeeze) the example works > as expected, so the problem appears to be platform specific. > Does this happen with "normal" bindings created through bind(), too > (which might point to some window manager issue) or with menu shortcuts > only (which might point to the tk magic that handles these behind the > scenes), and what is the exact platform ? I'm using Debian stable. I now don't think it is a Tk problem but rather that my window manager (GNOME 2) is for some reason discarding the first keypress. -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Go" - ISBN 0321774639 http://www.qtrac.eu/gobook.html From list at qtrac.plus.com Thu Jun 21 12:01:07 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Thu, 21 Jun 2012 11:01:07 +0100 Subject: [Tkinter-discuss] Problems with popup menus Message-ID: <20120621110107.1e175f80@dino> Hi, I am trying to create a popup menu that works like a pulldown menu, that is, it: (1) supports up and down arrow navigation and Enter to select, (2) supports keyboard mnemonics (e.g., type 'b' to select Blue item), (3) is cancelled with Escape. Here is an example that doesn't support any of the above (yet all of the above work automatically for menus in a menu bar). ############################################################ # Adapted from # http://www.java2s.com/Code/Python/GUI-Tk/Popupmenudemonstration.htm from tkinter import * class PopupMenuDemo(Frame): def __init__(self): Frame.__init__(self) self.pack(expand=YES, fill=BOTH) self.master.title("Popup Menu Demo") self.master.geometry("300x200") self.frame1 = Frame(self, bg="white") self.frame1.pack(expand= YES, fill=BOTH) self.popupMenu = Menu(self.frame1, tearoff=0) self.popupMenu.bind("", self.popupMenu.unpost) # Doesn't work self.popupMenu.bind("", self.popupMenu.unpost) # Doesn't work colors = ["White", "Red", "Green", "Blue"] self.selectedColor = StringVar() self.selectedColor.set(colors[0]) for color in colors: self.popupMenu.add_radiobutton(label=color, variable=self.selectedColor, underline=0, command=self.changeBackgroundColor) self.frame1.bind("", self.popUpMenu) def popUpMenu(self, event): self.popupMenu.post(event.x_root, event.y_root) def changeBackgroundColor(self): self.frame1.config(bg=self.selectedColor.get()) PopupMenuDemo().mainloop() ############################################################ Any advice on this would be appreciated:-) -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Rapid GUI Programming with Python and Qt" - ISBN 0132354187 http://www.qtrac.eu/pyqtbook.html From list at qtrac.plus.com Thu Jun 21 12:20:16 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Thu, 21 Jun 2012 11:20:16 +0100 Subject: [Tkinter-discuss] Problems with popup menus In-Reply-To: <20120621110107.1e175f80@dino> References: <20120621110107.1e175f80@dino> Message-ID: <20120621112016.2759a5f2@dino> Hi, Silly me! The solution is not to do any manual bindings and instead of calling Menu.post() call Menu.tk_popup() and everything works:-) On Thu, 21 Jun 2012 11:01:07 +0100 Mark Summerfield wrote: > Hi, > > I am trying to create a popup menu that works like a pulldown menu, that > is, it: > (1) supports up and down arrow navigation and Enter to select, > (2) supports keyboard mnemonics (e.g., type 'b' to select Blue item), > (3) is cancelled with Escape. > > Here is an example that doesn't support any of the above (yet all of the > above work automatically for menus in a menu bar). > > ############################################################ > # Adapted from > # http://www.java2s.com/Code/Python/GUI-Tk/Popupmenudemonstration.htm > from tkinter import * > > class PopupMenuDemo(Frame): > def __init__(self): > Frame.__init__(self) > self.pack(expand=YES, fill=BOTH) > self.master.title("Popup Menu Demo") > self.master.geometry("300x200") > self.frame1 = Frame(self, bg="white") > self.frame1.pack(expand= YES, fill=BOTH) > self.popupMenu = Menu(self.frame1, tearoff=0) > self.popupMenu.bind("", self.popupMenu.unpost) # Doesn't work > self.popupMenu.bind("", self.popupMenu.unpost) # Doesn't > work colors = ["White", "Red", "Green", "Blue"] > self.selectedColor = StringVar() > self.selectedColor.set(colors[0]) > for color in colors: > self.popupMenu.add_radiobutton(label=color, > variable=self.selectedColor, > underline=0, > command=self.changeBackgroundColor) > self.frame1.bind("", self.popUpMenu) > > def popUpMenu(self, event): > self.popupMenu.post(event.x_root, event.y_root) > > def changeBackgroundColor(self): > self.frame1.config(bg=self.selectedColor.get()) > > PopupMenuDemo().mainloop() > ############################################################ > > Any advice on this would be appreciated:-) -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Advanced Qt Programming" - ISBN 0321635906 http://www.qtrac.eu/aqpbook.html From mark at qtrac.eu Thu Jun 21 11:43:38 2012 From: mark at qtrac.eu (Mark Summerfield) Date: Thu, 21 Jun 2012 10:43:38 +0100 Subject: [Tkinter-discuss] Focus for first key press In-Reply-To: <20120621105230.7a270e6c.klappnase@web.de> References: <20120620095500.5bbf203f@dino> <20120620183358.e3bf2fa0.klappnase@web.de> <20120621080355.005192ed@dino> <20120621105230.7a270e6c.klappnase@web.de> Message-ID: <20120621104338.74cf80ac@dino> On Thu, 21 Jun 2012 10:52:30 +0200 Michael Lange wrote: > Hi Mark, > > Thus spoketh Mark Summerfield > unto us on Thu, 21 Jun 2012 08:03:55 +0100: > > > Below is an example. If I do > > > > $ python3 hello.pyw > > > > and then type Alt+F, the File menu does _not_ pop up. If I then type > > Alt+F a second (or subsequent) time it does. > > > > It seems that Tkinter is ignoring the *very first keypress*. If I press > > any key (e.g., Space, or x) and _then_ Alt+F, the File menu pops up as > > it should. > > I cannot reproduce this behavior, here (debian squeeze) the example works > as expected, so the problem appears to be platform specific. > Does this happen with "normal" bindings created through bind(), too > (which might point to some window manager issue) or with menu shortcuts > only (which might point to the tk magic that handles these behind the > scenes), and what is the exact platform ? I'm using Debian stable. I now don't think it is a Tk problem but rather that my window manager (GNOME 2) is for some reason discarding the first keypress. -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Advanced Qt Programming" - ISBN 0321635906 http://www.qtrac.eu/aqpbook.html From list at qtrac.plus.com Sun Jun 24 09:42:33 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Sun, 24 Jun 2012 08:42:33 +0100 Subject: [Tkinter-discuss] BooleanVar() etc. Message-ID: <20120624084233.1d1928d1@dino> Hi, Right now it is possible to do bv = BooleanVar() bv.set(any_old_rubbish) b = bv.get() # b is an int not a bool I've reported this as a bug and commented that I think that BooleanVar, IntVar, FloatVar, and StringVar should honor the type in their names (i.e., bool, int, float, str). If this matters to you could you look at the issue and maybe comment? http://bugs.python.org/issue15133 -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Go" - ISBN 0321774639 http://www.qtrac.eu/gobook.html From klappnase at web.de Sun Jun 24 19:44:42 2012 From: klappnase at web.de (Michael Lange) Date: Sun, 24 Jun 2012 19:44:42 +0200 Subject: [Tkinter-discuss] BooleanVar() etc. In-Reply-To: <20120624084233.1d1928d1@dino> References: <20120624084233.1d1928d1@dino> Message-ID: <20120624194442.46843f35.klappnase@web.de> Hi Mark, Thus spoketh Mark Summerfield unto us on Sun, 24 Jun 2012 08:42:33 +0100: > Hi, > > Right now it is possible to do > > bv = BooleanVar() > bv.set(any_old_rubbish) > b = bv.get() # b is an int not a bool > > I've reported this as a bug and commented that I think that BooleanVar, > IntVar, FloatVar, and StringVar should honor the type in their names > (i.e., bool, int, float, str). > > If this matters to you could you look at the issue and maybe comment? > > http://bugs.python.org/issue15133 I've been there and spent my 2 cents ;) Now I just wanted to leave a comment here, too. First, the return value of get() is not neccessarily an int: >>> b = BooleanVar() >>> b.set('yes') >>> b.get() True >>> b.set('1') >>> b.get() True >>> b.set(1) >>> b.get() 1 >>> b.set(True) >>> b.get() 1 >>> b.set('true') >>> b.get() True At the first glance this seems somewhat erratic, nevertheless there is an obvious pattern: apparently all the strings that tcl accepts as boolean values cause get() to return True / False whereas the special values True / False / 0 / 1 passed to set() cause get() to return 1 / 0. This might be considered a bug, but it is not a BooleanVar speciality, but the behavior of tkapp.getboolean() and we encounter it everywhere in tkinter. The fact that values like 'yes' are accepted as boolean values does not seem to make sense if you think of the BooleanVar as a *Python* boolean object, but if you think of it as a Python representation of a *Tcl* boolean it makes a lot of sense. Then, your above observation that you can pass "any_old_rubbish" to set() and get() will in return give you an integer is not exactly correct: >>> b.set(1.5) >>> b.get() Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.1/tkinter/__init__.py", line 316, in get return self._tk.getboolean(self._tk.globalgetvar(self._name)) TypeError: must be string, not float >>> b.set([]) >>> b.get() Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.1/tkinter/__init__.py", line 316, in get return self._tk.getboolean(self._tk.globalgetvar(self._name)) _tkinter.TclError: expected boolean value but got "[]" and so on. I agree that it seems odd that you need to call get() to see the error. OTOH, the special thing about the BooleanVariable is that get() will always return a boolean (at least if we accept 0 / 1 as bool), no one promised that set () only accepts bool values: >>> b.set.__doc__ 'Set the variable to VALUE.' >>> b.get.__doc__ 'Return the value of the variable as a bool.' >>> b.__doc__ 'Value holder for boolean variables.' >>> The problem with set() is of course, that it must accept anything that Tcl might use as boolean, otherwise we might run into trouble if somewhere the return value of some tcl command is directly passed to set() . I think if we do not consider the BooleanVar to be a Python boolean object but rather a convenience object for handling Tcl boolean values these limitations won't hurt too much. In fact I have been using BooleanVars for many years now, and they worked so well that I never even noticed these oddities. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. War is never imperative. -- McCoy, "Balance of Terror", stardate 1709.2 From list at qtrac.plus.com Mon Jun 25 18:09:46 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Mon, 25 Jun 2012 17:09:46 +0100 Subject: [Tkinter-discuss] Text undo/redo stack Message-ID: <20120625170946.34ff6bb7@dino> Hi, I can enable/disable an undo button for a Text widget depending on Text.edit_modified(); i.e., if it is modified then I can safely call undo. But what I'd really like to do is just check the undo *and redo* stacks to see whether they are empty and enable/disable based on that. Is this possible? Thanks! -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Rapid GUI Programming with Python and Qt" - ISBN 0132354187 http://www.qtrac.eu/pyqtbook.html From list at qtrac.plus.com Thu Jun 28 15:41:12 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Thu, 28 Jun 2012 14:41:12 +0100 Subject: [Tkinter-discuss] setting a minsize for gridded windows Message-ID: <20120628144112.0ddf1f32@dino> Hi, I want to set a minsize for a window. Sometimes the window is gridded and sometimes not. When it is gridded its winfo_reqwidth() is in characters not pixels and vice versa. Is there any way to tell whether it is using characters or pixels so that I can call minsize() with sensible values (e.g., minsize(100, 100) if pixels but minsize(10, 10) if characters). Thanks! -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Advanced Qt Programming" - ISBN 0321635906 http://www.qtrac.eu/aqpbook.html From klappnase at web.de Thu Jun 28 18:55:40 2012 From: klappnase at web.de (Michael Lange) Date: Thu, 28 Jun 2012 18:55:40 +0200 Subject: [Tkinter-discuss] setting a minsize for gridded windows In-Reply-To: <20120628144112.0ddf1f32@dino> References: <20120628144112.0ddf1f32@dino> Message-ID: <20120628185540.53bccebb.klappnase@web.de> Hi Mark, Thus spoketh Mark Summerfield unto us on Thu, 28 Jun 2012 14:41:12 +0100: > Hi, > > I want to set a minsize for a window. Sometimes the window is gridded > and sometimes not. When it is gridded its winfo_reqwidth() is in > characters not pixels and vice versa. > > Is there any way to tell whether it is using characters or pixels so > that I can call minsize() with sensible values (e.g., minsize(100, 100) > if pixels but minsize(10, 10) if characters). According to man wm: (...) the return value is a Tcl list containing four elements corresponding to the current baseWidth, baseHeight, widthInc, and heightInc; if window is not currently gridded, then an empty string is returned. So you should be able to check the window's "grid state" easily with wm_grid(), if it's None, the window is not gridded: >>> root = Tk() >>> print root.wm_grid() None >>> print root.wm_grid(100, 100, 10, 10) None >>> print root.wm_grid() (100, 100, 10, 10) >>> Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. "What terrible way to die." "There are no good ways." -- Sulu and Kirk, "That Which Survives", stardate unknown From list at qtrac.plus.com Fri Jun 29 10:27:34 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Fri, 29 Jun 2012 09:27:34 +0100 Subject: [Tkinter-discuss] setting a minsize for gridded windows In-Reply-To: <20120628185540.53bccebb.klappnase@web.de> References: <20120628144112.0ddf1f32@dino> <20120628185540.53bccebb.klappnase@web.de> Message-ID: <20120629092734.388d71a6@dino> Hi Michael, On Thu, 28 Jun 2012 18:55:40 +0200 Michael Lange wrote: > Hi Mark, > > Thus spoketh Mark Summerfield > unto us on Thu, 28 Jun 2012 14:41:12 +0100: > [snip] > So you should be able to check the window's "grid state" easily with > wm_grid(), if it's None, the window is not gridded: > > >>> root = Tk() > >>> print root.wm_grid() > None > >>> print root.wm_grid(100, 100, 10, 10) > None > >>> print root.wm_grid() > (100, 100, 10, 10) That worked great---thanks! -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Rapid GUI Programming with Python and Qt" - ISBN 0132354187 http://www.qtrac.eu/pyqtbook.html