From xsxcn at hotmail.com Thu Oct 1 02:42:48 2009 From: xsxcn at hotmail.com (Protosssword) Date: Thu, 1 Oct 2009 08:42:48 +0800 Subject: [Tkinter-discuss] How to export the image drawn by canvas? Message-ID: Dears,: I use canvas to make animation by continuously displaying objects. Now I want to export what is displayed in canvas to an image file(.bmp, jpeg,png,... is OK) Is there such function in tkinter and how can I attain this? Thank you very much! Shengxu _________________________________________________________________ Messenger10????????????? http://10.msn.com.cn -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Thu Oct 1 12:39:31 2009 From: klappnase at web.de (Michael Lange) Date: Thu, 1 Oct 2009 12:39:31 +0200 Subject: [Tkinter-discuss] How to export the image drawn by canvas? In-Reply-To: References: Message-ID: <20091001123931.ad2536dd.klappnase@web.de> Hi, On Thu, 1 Oct 2009 08:42:48 +0800 Protosssword wrote: > > Dears,: > > I use canvas to make animation by continuously displaying objects. > Now I want to export what is displayed in canvas to an image file > (.bmp, jpeg,png,... is OK) Is there such function in tkinter and how > can I attain this? > You can use the canvases postscript() method to export the whole canvas or a part of it to a postscript file or alternatively let postscript() return the postscript data. If necessary, you can use PIL to convert the postscript into png or jpeg or so. I hope this helps Michael From lionkimbro at gmail.com Thu Oct 1 04:17:20 2009 From: lionkimbro at gmail.com (Lion Kimbro) Date: Wed, 30 Sep 2009 19:17:20 -0700 Subject: [Tkinter-discuss] How to export the image drawn by canvas? In-Reply-To: References: Message-ID: <497072fd0909301917v718255eua2f16af060e61014@mail.gmail.com> I don't believe there's a function. I've read about people making functions that save a postscript [1], and open a command shell to instruct ImageMagick to conver it, and I've read about people using software that bridges tkinter with PIL [2]. As for storing animations, I've never heard of people doing that with tkinter. Related wiki articles: * http://tkinter.unpythonic.net/wiki/Images [1] tkinter.Canvas.postscript: http://infohost.nmt.edu/tcc/help/pubs/tkinter/canvas-methods.html [2] the ImageTk module http://www.pythonware.com/library/pil/handbook/imagetk.htm 2009/9/30 Protosssword > Dears,: > > I use canvas to make animation by continuously displaying objects. > Now I want to export what is displayed in canvas to an image file(.bmp, > jpeg,png,... is OK) > Is there such function in tkinter and how can I attain this? > > Thank you very much! > > Shengxu > > ------------------------------ > ???? MSN ??????Messenger ????? ?????? > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From andwhay at gmail.com Sat Oct 3 07:00:13 2009 From: andwhay at gmail.com (Nessuss) Date: Fri, 2 Oct 2009 22:00:13 -0700 (PDT) Subject: [Tkinter-discuss] Tkinter on OS X wont import Message-ID: <25725811.post@talk.nabble.com> Hi, I've been trying to work with some python programs that use Tkinter in them but when python tries to import the Tkinter package I get this error: import Tkinter File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py", line 38, in import _tkinter # If this fails your Python may not be configured for Tk ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_tkinter.so, 2): Library not loaded: /opt/local/lib/libX11.6.dylib Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_tkinter.so Reason: no suitable image found. Did find: /opt/local/lib/libX11.6.dylib: mach-o, but wrong architecture I can't seem to figure out the problem, some time ago I installed using macports tcl and tk, everything was working then. But now it gives the above error. In between the time Tkinter was last working and now I did upgrade to Snow Leopard. If anyone can help me out here, that would be great. -- View this message in context: http://www.nabble.com/Tkinter-on-OS-X-wont-import-tp25725811p25725811.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From michael.odonnell at uam.es Sun Oct 4 08:55:11 2009 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Sun, 4 Oct 2009 08:55:11 +0200 Subject: [Tkinter-discuss] Tkinter on OS X wont import In-Reply-To: <25725811.post@talk.nabble.com> References: <25725811.post@talk.nabble.com> Message-ID: <47e491110910032355j3edc8d00i393f26c01bdc0020@mail.gmail.com> Hi Nessus, I had the same problem a while back and fixed it after some messing around. Stupidly I did't write down my fix. I seem to remember that I had to update some software which was NOT python. Maybe XCode. Make sure you have the most recent versions of XCODE. Sorry I cannot help more definitively. Mick On Sat, Oct 3, 2009 at 7:00 AM, Nessuss wrote: > > Hi, > > I've been trying to work with some python programs that use Tkinter in them > but when python tries to import the Tkinter package I get this error: > > > import Tkinter > ?File > "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py", > line 38, in > ? ?import _tkinter # If this fails your Python may not be configured for Tk > ImportError: > dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_tkinter.so, > 2): Library not loaded: /opt/local/lib/libX11.6.dylib > ?Referenced from: > /opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_tkinter.so > ?Reason: no suitable image found. ?Did find: > ? ? ? ?/opt/local/lib/libX11.6.dylib: mach-o, but wrong architecture > > > I can't seem to figure out the problem, some time ago I installed using > macports tcl and tk, everything was working then. But now it gives the above > error. In between the time Tkinter was last working and now I did upgrade to > Snow Leopard. If anyone can help me out here, that would be great. > -- > View this message in context: http://www.nabble.com/Tkinter-on-OS-X-wont-import-tp25725811p25725811.html > Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > From kw at codebykevin.com Wed Oct 7 16:06:40 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 07 Oct 2009 10:06:40 -0400 Subject: [Tkinter-discuss] Execute Python callback from Tk widgets Message-ID: <4ACCA070.3050603@codebykevin.com> Hi all, I'm running into some difficulty in wrapping a Tk widget from Python in a way that will allow me to execute Python callbacks/commands. I'm trying to incorporate widgets from TclMacBag (http://tclmacbag.autons.net/) into one of my Tkinter programs. Specifically, I'm trying to use the "stylebutton" widget. At their base, the TclMacBag stylebuttons are just ttk::buttons with a custom style. However, they are constructed as megawidgets, their internal API is quite complex, and so getting at their underlying button and style implementation from Tkinter is difficult. My current approach is to define a simple Tcl/Tk package that exposes the functionality I need, and then use self.tk.call() to access this from Tkinter. Here's an abbreviated example: ##Tcl code in "macstylebutton" package proc macstylebutton {w child img cmd layout msg row column } { ::tclmacbag::stylebutton $w.$child -image $img -style $layout -command $cmd grid $w.$child -row $row -column $column balloon $w.$child $msg } #Python function def styleButton(self, parent, child, img, cmd, style, msg, row, column): self.tk.call('package', 'require', 'macstylebutton') self.tk.call('macstylebutton', parent, child, img, cmd, style, msg, row, column) #Python GUI code that calls the function self.deletebutton=self.styleButton(self.topframe, 'delete', self.logout, lambda: self.authorizeCommand(self.deletePackage), 'mail', 'Delete package', 0, 2) This code lays the buttons out correctly, but the Python callback is not executed. It seems to be correctly set up; running "print cmd" yields output like this: > but the actual callback doesn't fire. My theory as to the problem is this: it appears that the widget is responding to the "cmd" parameter as a Tcl command, and since it's actually a Python command, nothing's happening. I know Python/Tkinter can execute Tcl commands through 'call' or 'eval,' but it doesn't appear that Python commands can be passed to raw Tk widgets. Indeed, I had tried to simply configure the buttons via something like 'self.deleteButton.configure(command=foo'), but Tkinter returned an error--something about a NoneType object lacking a 'configure' method. My question is this: how can I get Python callbacks to fire when a raw Tk widget is being called via 'self.tk.call'? Do I have to write a fancy wrapper that turns the widget into a Python object that will respond to Python callbacks, or is there a simpler way to do this? Thanks, Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From rowen at uw.edu Wed Oct 7 21:00:20 2009 From: rowen at uw.edu (Russell E. Owen) Date: Wed, 07 Oct 2009 12:00:20 -0700 Subject: [Tkinter-discuss] Execute Python callback from Tk widgets References: <4ACCA070.3050603@codebykevin.com> Message-ID: In article <4ACCA070.3050603 at codebykevin.com>, Kevin Walzer wrote: >... > My question is this: how can I get Python callbacks to fire when a raw > Tk widget is being called via 'self.tk.call'? Do I have to write a fancy > wrapper that turns the widget into a Python object that will respond to > Python callbacks, or is there a simpler way to do this? I use this class (from the RO package's module RO.TkUtil): class TclFunc: """Register a python function as a tcl function. Based on Tkinter's _register method (which, being private, I prefer not to use explicitly). If the function call fails, a traceback is printed. Please call deregister when you no longer want the tcl function to exist. """ tkApp = None def __init__(self, func, debug=False): if self.tkApp == None: self.tkApp =Tkinter.Frame().tk self.func = func self.tclFuncName = "pyfunc%s" % (id(self),) self.debug = bool(debug) try: self.tclFuncName += str(func.__name__) except AttributeError: pass if self.debug: print "registering tcl function %s for python function %s" % (self.tclFuncName, func) self.tkApp.createcommand(self.tclFuncName, self) def __call__(self, *args): try: self.func(*args) except (SystemExit, KeyboardInterrupt): raise except Exception, e: sys.stderr.write("tcl function %s failed: %s\n" % (self.tclFuncName, e)) traceback.print_exc(file=sys.stderr) def deregister(self): """Deregister callback and delete reference to python function. Safe to call if already deregistered. """ if self.debug: print "%r.deregister()" % (self,) if not self.func: if self.debug: print "already deregistered" return try: self.tkApp.deletecommand(self.tclFuncName) except Tkinter.TclError, e: if self.debug: print "deregistering failed: %r" % (e,) pass self.func = None def __repr__(self): return "%s(%s)" % (self.__class__.__name__, self.tclFuncName) def __str__(self): return self.tclFuncName From kw at codebykevin.com Thu Oct 8 01:17:03 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 07 Oct 2009 19:17:03 -0400 Subject: [Tkinter-discuss] Execute Python callback from Tk widgets In-Reply-To: References: <4ACCA070.3050603@codebykevin.com> Message-ID: <4ACD216F.4010006@codebykevin.com> Hi Russell, On 10/7/09 3:00 PM, Russell E. Owen wrote: > > I use this class (from the RO package's module RO.TkUtil): > > class TclFunc: > """Register a python function as a tcl function. > Based on Tkinter's _register method (which, being private, > I prefer not to use explicitly). Thanks for this reference. It led me directly to the "register" method in Tkinter. Now my commands are as simple as self.register(self.infoTable), and they work. Best, Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From wwwwar3com at gmail.com Wed Oct 14 05:14:35 2009 From: wwwwar3com at gmail.com (BlackKnight) Date: Tue, 13 Oct 2009 23:14:35 -0400 Subject: [Tkinter-discuss] Need help on gui focus l Message-ID: <4AD5421B.3070000@gmail.com> Hi folks, I am using Tkinter to do a simple GUI for my program. It contains A MainGui and A ChildGui: A button on the MainGUI will popout the childgui. On the childgui there is a browse button which popout a dialog to allow user to browser and choose a file. I have no problem at doing them. The problem is after the uesr choose a file the focus will return to the MainGui intead of the childgui. The child gui just go hide behind the Main. I've tried focus_set, focus_force but none of them seem work. I did some research but found nothing working. It's not a big problem, but is really really annoying. (Actually I notice the examples from some python book I am reading has the exact same problem. The author even tried to spawn the child gui away from the main one, so when the focus return from the browse dialog , the maingui won't block the child one~~ Is that how tkinter should work?) Any suggestions? Thanks in advance~~ Frank From klappnase at web.de Wed Oct 14 21:03:16 2009 From: klappnase at web.de (Michael Lange) Date: Wed, 14 Oct 2009 21:03:16 +0200 Subject: [Tkinter-discuss] Need help on gui focus l In-Reply-To: <4AD5421B.3070000@gmail.com> References: <4AD5421B.3070000@gmail.com> Message-ID: <20091014210316.acd79251.klappnase@web.de> Hi, On Tue, 13 Oct 2009 23:14:35 -0400 BlackKnight wrote: > Hi folks, > > I am using Tkinter to do a simple GUI for my program. > > It contains A MainGui and A ChildGui: > A button on the MainGUI will popout the childgui. > On the childgui there is a browse button which popout a dialog to > allow user to browser and choose a file. > > I have no problem at doing them. > > The problem is after the uesr choose a file the focus will return to > the MainGui intead of the childgui. The child gui just go hide behind > the Main. > > I've tried focus_set, focus_force but none of them seem work. > > I did some research but found nothing working. It's not a big problem, > but is really really annoying. > (Actually I notice the examples from some python book I am reading has > the exact same problem. The author even tried to spawn the child gui > away from the main one, so when the focus return from the browse > dialog , the maingui won't block the child one~~ Is that how tkinter > should work?) > I cannot reproduce this behavior here (linux), maybe it is a platform specific problem ? I tried the follwing which works for me as expected: ### CODE ### from Tkinter import * import tkFileDialog root = Tk() top = Toplevel() top.withdraw() top.protocol('WM_DELETE_WINDOW', top.withdraw) def filedialog(): print tkFileDialog.askopenfilename() b0 = Button(top, text='filedialog', command=filedialog) b0.pack(padx=100, pady=100) def popup(): top.deiconify() b0.focus_set() b1 = Button(root, text='popup', command=popup) b1.pack(padx=100, pady=100) root.mainloop() ### CODE ### In case I just did not understand exactly your problem, could you post a short code snippet here that shows the problem and tell us which platform you are using, please ? Michael From msa01 at bitflipper.ca Wed Oct 14 22:07:30 2009 From: msa01 at bitflipper.ca (Cam Farnell) Date: Wed, 14 Oct 2009 17:07:30 -0300 Subject: [Tkinter-discuss] Need help on gui focus l In-Reply-To: <20091014210316.acd79251.klappnase@web.de> References: <4AD5421B.3070000@gmail.com> <20091014210316.acd79251.klappnase@web.de> Message-ID: <4AD62F82.2030803@bitflipper.ca> The code given exhibits the problem on my Ubuntu Linux box. For the sake of clarity I enumerate three windows involved in this code: - The MAIN window which has a button marked "popup" in it. - The CHILD windows which has a button marked "filedialog" in it. - The OPEN window which is the tkFileDialog On my machine clicking on the "popup" and "filedialog" buttons works ok, but once you select a file and click OPEN, then what is on top and visible is the MAIN window whereas what the original poster wanted was to see the CHILD window. Even worse, if (starting from scratch again) you click the "popup" button, then drag the resulting CHILD window to a slightly new position then click the "filedialog" button, the OPEN window appears *under* the CHILD window which seems less than useful. Cam Farnell Michael Lange wrote: > I cannot reproduce this behavior here (linux), maybe it is a platform > specific problem ? I tried the follwing which works for me as expected: > > ### CODE ### > from Tkinter import * > import tkFileDialog > > root = Tk() > > top = Toplevel() > top.withdraw() > top.protocol('WM_DELETE_WINDOW', top.withdraw) > > def filedialog(): > print tkFileDialog.askopenfilename() > > b0 = Button(top, text='filedialog', command=filedialog) > b0.pack(padx=100, pady=100) > > def popup(): > top.deiconify() > b0.focus_set() > > b1 = Button(root, text='popup', command=popup) > b1.pack(padx=100, pady=100) > root.mainloop() > ### CODE ### > > In case I just did not understand exactly your problem, > could you post a short code snippet here that shows > the problem and tell us which platform you are using, please ? > > Michael From klappnase at web.de Thu Oct 15 09:23:21 2009 From: klappnase at web.de (Michael Lange) Date: Thu, 15 Oct 2009 09:23:21 +0200 Subject: [Tkinter-discuss] Need help on gui focus l In-Reply-To: <4AD62F82.2030803@bitflipper.ca> References: <4AD5421B.3070000@gmail.com> <20091014210316.acd79251.klappnase@web.de> <4AD62F82.2030803@bitflipper.ca> Message-ID: <20091015092321.98fd0874.klappnase@web.de> Hi, On Wed, 14 Oct 2009 17:07:30 -0300 Cam Farnell wrote: > The code given exhibits the problem on my Ubuntu Linux box. For the > sake of clarity I enumerate three windows involved in this code: > > - The MAIN window which has a button marked "popup" in it. > - The CHILD windows which has a button marked "filedialog" in it. > - The OPEN window which is the tkFileDialog > > On my machine clicking on the "popup" and "filedialog" buttons works > ok, but once you select a file and click OPEN, then what is on top > and visible is the MAIN window whereas what the original poster > wanted was to see the CHILD window. Even worse, if (starting from > scratch again) you click the "popup" button, then drag the resulting > CHILD window to a slightly new position then click the "filedialog" > button, the OPEN window appears *under* the CHILD window which seems > less than useful. > You are right, this actually sounds less than useful and it is surely not the way it is supposed to be. I cannot reproduce this here (debian lenny, Python-2.5.2, Tk-8.4.19) though. I guess this is most likely a bug in your version of Tk. I wrote a tiny tcl script that does basically the same as the python code from my last post, you can try if it exhibits the same bug, then we could at least be sure that it's not python that causes the bug. ###CODE### #!/usr/bin/env wish toplevel .t wm withdraw .t wm protocol .t WM_DELETE_WINDOW {wm withdraw .t} button .t.b0 -text "filedialog" -command tk_getOpenFile pack .t.b0 -padx 100 -pady 100 button .b1 -text "popup" -command {wm deiconify .t} pack .b1 -padx 100 -pady 100 ###CODE### Michael From msa01 at bitflipper.ca Thu Oct 15 11:15:30 2009 From: msa01 at bitflipper.ca (Cam Farnell) Date: Thu, 15 Oct 2009 06:15:30 -0300 Subject: [Tkinter-discuss] Need help on gui focus l In-Reply-To: <20091015092321.98fd0874.klappnase@web.de> References: <4AD5421B.3070000@gmail.com> <20091014210316.acd79251.klappnase@web.de> <4AD62F82.2030803@bitflipper.ca> <20091015092321.98fd0874.klappnase@web.de> Message-ID: <4AD6E832.5030609@bitflipper.ca> The behavior of your tcl script is identical to the Python code so it's not Python causing the problem. I'm running Ubuntu 8.04 (Hardy), Python 2.5.2 and I don't know enough about tcl to find out its version. The file /usr/share/doc/tk8.4/README says it is 8.4.16. Cam Michael Lange wrote: > Hi, > > On Wed, 14 Oct 2009 17:07:30 -0300 > Cam Farnell wrote: > >> The code given exhibits the problem on my Ubuntu Linux box. For the >> sake of clarity I enumerate three windows involved in this code: >> >> - The MAIN window which has a button marked "popup" in it. >> - The CHILD windows which has a button marked "filedialog" in it. >> - The OPEN window which is the tkFileDialog >> >> On my machine clicking on the "popup" and "filedialog" buttons works >> ok, but once you select a file and click OPEN, then what is on top >> and visible is the MAIN window whereas what the original poster >> wanted was to see the CHILD window. Even worse, if (starting from >> scratch again) you click the "popup" button, then drag the resulting >> CHILD window to a slightly new position then click the "filedialog" >> button, the OPEN window appears *under* the CHILD window which seems >> less than useful. >> > > You are right, this actually sounds less than useful and it is surely > not the way it is supposed to be. I cannot reproduce this here (debian > lenny, Python-2.5.2, Tk-8.4.19) though. I guess this is most likely a > bug in your version of Tk. > I wrote a tiny tcl script that does basically the same as the python > code from my last post, you can try if it exhibits the same bug, then > we could at least be sure that it's not python that causes the bug. > > ###CODE### > #!/usr/bin/env wish > > toplevel .t > wm withdraw .t > wm protocol .t WM_DELETE_WINDOW {wm withdraw .t} > button .t.b0 -text "filedialog" -command tk_getOpenFile > pack .t.b0 -padx 100 -pady 100 > button .b1 -text "popup" -command {wm deiconify .t} > pack .b1 -padx 100 -pady 100 > ###CODE### > > Michael From klappnase at web.de Thu Oct 15 12:12:36 2009 From: klappnase at web.de (Michael Lange) Date: Thu, 15 Oct 2009 12:12:36 +0200 Subject: [Tkinter-discuss] Need help on gui focus l In-Reply-To: <4AD6E832.5030609@bitflipper.ca> References: <4AD5421B.3070000@gmail.com> <20091014210316.acd79251.klappnase@web.de> <4AD62F82.2030803@bitflipper.ca> <20091015092321.98fd0874.klappnase@web.de> <4AD6E832.5030609@bitflipper.ca> Message-ID: <20091015121236.3818a119.klappnase@web.de> On Thu, 15 Oct 2009 06:15:30 -0300 Cam Farnell wrote: > The behavior of your tcl script is identical to the Python code so > it's not Python causing the problem. I'm running Ubuntu 8.04 (Hardy), > Python 2.5.2 and I don't know enough about tcl to find out its > version. The file /usr/share/doc/tk8.4/README says it is 8.4.16. > I asked synaptic for the version :) So if it is Tk which is broken, in case that upgrading Tk is not an option, maybe you can try a workaround using the Toplevel's lift() method . Michael From mick at sulley.info Mon Oct 19 17:29:27 2009 From: mick at sulley.info (MickSulley) Date: Mon, 19 Oct 2009 08:29:27 -0700 (PDT) Subject: [Tkinter-discuss] Newbie question - displaying data Message-ID: <25960335.post@talk.nabble.com> Hi, I am new to TKinter and struggling somewhat. I have a Python program that reads a number of temperatures from sensors in tanks and pipework, that is working fine. I now want to display those temperatures, ideally a simple diagram of the pipework with boxes displaying the values. I don't need any user input, it just runs forever once started My initial thought was to use a text widget for the whole page and update the areas that show the values. Is that the best way to do it? Can anyone give me some pointers on constructing the program? Thanks Mick -- View this message in context: http://www.nabble.com/Newbie-question---displaying-data-tp25960335p25960335.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From lionkimbro at gmail.com Mon Oct 19 19:09:24 2009 From: lionkimbro at gmail.com (Lion Kimbro) Date: Mon, 19 Oct 2009 10:09:24 -0700 Subject: [Tkinter-discuss] Newbie question - displaying data In-Reply-To: <25960335.post@talk.nabble.com> References: <25960335.post@talk.nabble.com> Message-ID: <497072fd0910191009p43711e9anb1ff319058f53f28@mail.gmail.com> This sounds like a great use for **the canvas widget.** 1. Draw layout with canvas lines and rectangles. 2. Draw text representing sensor readings onto canvas. 3. Refresh display by reconfiguring text, once a second. The great thing about canvas is that -- once you've got text placed on it, you can just alter the text via the canvas.itemconfigure method. Here's a rendering of your program: ------------------------------------------------------------------------ from tkinter import * class BasicCanvasFrame1(Canvas): """Basic canvas frame. (Strictly, NOT a Frame -- but we're using it sort of like one.) For convenience, there is a size parameter offering typical sizes: 320x200 "CGA" 640x480 "VGA" 1024x768 "XGA" 1280x1024 "SVGA" "FULL" -- full screen mode For organizing's sake, the BasicCanvasFrame suggests a function, "draw," for drawing onto it with. Also, there are some common event registrations, so that you do not need to register them yourself: * mouse clicks, * mouse motion, * key presses """ def __init__(self, title="Untitled Frame", size="VGA", width=None, height=None, enable_per_second=False, master=None, external_delegate=None): self.external_delegate = external_delegate # 1. Initialize Frame size = size.upper() if size != "FULL": if width is None: width = {"CGA": 320, "VGA": 640, "XGA": 1024, "SVGA": 1280}[size] if height is None: height = {"CGA": 200, "VGA": 480, "XGA": 768, "SVGA": 1024}[size] Canvas.__init__(self, master, width=width, height=height) self.master.title(title) else: Canvas.__init__(self, master) (width, height) = tk_fullscreen(self) self.configure(width=width, height=height) self.pack(anchor=N+W, fill='both', expand='yes') # Fix origin displayer, per: # http://tkinter.unpythonic.net/wiki/Widgets/Canvas?highlight=(canvas) self.xview_moveto(0) self.yview_moveto(0) # 2. Bind self.bind("", self.left_click) self.bind("", self.right_click) #self.bind("", self.keypress) self.bind_all('', self.keypress) self.bind_all('', self.keypress) self.bind_all('', self.keypress) # self.bind_all('', self.keypress) self.bind("", self.motion) # 3. Draw self.wait_visibility() self.draw() if external_delegate is not None: external_delegate.draw(self) # 4. Turn on per-second events, if requested if enable_per_second: self.after(1000, self._per_second) def _per_second(self): self.per_second() self.after(1000, self._per_second) def draw(self): pass def left_click(self, evt): pass def right_click(self, evt): pass def keypress(self, evt): """Key pressed. evt.keysym -- super-friendly key symbol evt.char -- For textual characters, this is the char. evt.keycode -- For recognizing things like... """ pass def motion(self, evt): pass def per_second(self): pass class MickSulleysTemperatureSensor(BasicCanvasFrame1): def __init__(self, **args): BasicCanvasFrame1.__init__( self, title="Mike Sulley's Temperature Sensor", width=130*3, height=75*3, enable_per_second=True) def draw(self): self.create_rectangle(45*3,35*3,85*3,55*3, outline="blue") for (x1,y1,x2,y2) in [(15*3,15*3, 55*3,15*3), (55*3,15*3, 55*3,35*3), (15*3,45*3, 45*3,45*3), (85*3,45*3,105*3,45*3)]: self.create_line(x1,y1,x2,y2) self.temperature_item = {} for (x,y,name) in [( 15*3,15*3, "A"), ( 55*3,35*3, "B"), ( 15*3,45*3, "C"), ( 45*3,45*3, "D"), ( 85*3,45*3, "E"), (105*3,45*3, "F")]: text_item = self.create_text(x+5,y+2, text="<"+name+">", anchor=NW) self.temperature_item[name] = text_item def get_temperature(self, sensor_name): """Put your code in here.""" import random return random.randint(72,95) def per_second(self): for (sensor_name, text_item) in self.temperature_item.items(): cur_temperature = self.get_temperature(sensor_name) self.itemconfigure(text_item, text="%s: %d" % (sensor_name, cur_temperature)) MickSulleysTemperatureSensor().mainloop() ------------------------------------------------------------------------ (This is longer than is strictly necessary; I'm reusing BasicCanvasFrame1 from my notes to make this quickly.) The main points of interest are: * MickSulleysTemperatureSensor.draw: (the drawing code) * MickSulleysTemperatureSensor.per_second: (the itemconfigure line) * BasicCanvasFrame1.__init__: (Canvas initialization, packing code, Canvas.after initialization) * BasicCanvasFrame1._per_second: (Canvas.after continuity) Feel free to adapt and reuse the code here. (If you experiment with Canvas, I might suggest using BasicCanvasFrame1 yourself -- it has made my own experimentation a lot easier.) Sincerely, Lion Kimbro On Mon, Oct 19, 2009 at 8:29 AM, MickSulley wrote: > > Hi, > > I am new to TKinter and struggling somewhat. > > I have a Python program that reads a number of temperatures from sensors in > tanks and pipework, that is working fine. I now want to display those > temperatures, ideally a simple diagram of the pipework with boxes > displaying > the values. I don't need any user input, it just runs forever once started > > My initial thought was to use a text widget for the whole page and update > the areas that show the values. > > Is that the best way to do it? Can anyone give me some pointers on > constructing the program? > > Thanks > > Mick > -- > View this message in context: > http://www.nabble.com/Newbie-question---displaying-data-tp25960335p25960335.html > Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: From francis_ryan_70 at hotmail.com Thu Oct 22 17:46:19 2009 From: francis_ryan_70 at hotmail.com (buckr02) Date: Thu, 22 Oct 2009 08:46:19 -0700 (PDT) Subject: [Tkinter-discuss] Grid Geometry Manager & ImageTk.PhotoImage Message-ID: <26012393.post@talk.nabble.com> I cannot for the life of me figure this out. I am trying to create a program that will display images and have some functions to go along with it. I am using the grid manager to organize everything, and the basic framework is as such: * 2x2 grid * Row 0, Column 0 is first image * Row 0, Column 1 is second image * Row 1, Column 0 is first toolbar * Row 1, Column 1 is second toolbar I am having trouble with the images, however, as they are being cut off (only part of the image is being shown). I am using Canvas objects to hold the images. I was able to throw in a few lines to fix most of the problems, but since it isn't perfect, I'd like to get to the bottom of it. The only noticeable problem left is that if you load a vertical picture, there is space left to the right of the image that is counted as part of the canvas. I uploaded the Python code and an image which demonstrates the problem. http://www.nabble.com/file/p26012393/ForUpload.py ForUpload.py http://www.nabble.com/file/p26012393/DSC_1108.JPG DSC_1108.JPG -- View this message in context: http://www.nabble.com/Grid-Geometry-Manager---ImageTk.PhotoImage-tp26012393p26012393.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From klappnase at web.de Thu Oct 22 22:24:01 2009 From: klappnase at web.de (Michael Lange) Date: Thu, 22 Oct 2009 22:24:01 +0200 Subject: [Tkinter-discuss] Grid Geometry Manager & ImageTk.PhotoImage In-Reply-To: <26012393.post@talk.nabble.com> References: <26012393.post@talk.nabble.com> Message-ID: <20091022222401.e5e670e8.klappnase@web.de> Hi, On Thu, 22 Oct 2009 08:46:19 -0700 (PDT) buckr02 wrote: (...) > > I am having trouble with the images, however, as they are being cut > off (only part of the image is being shown). I am using Canvas > objects to hold the images. > > I was able to throw in a few lines to fix most of the problems, but > since it isn't perfect, I'd like to get to the bottom of it. The > only noticeable problem left is that if you load a vertical picture, > there is space left to the right of the image that is counted as part > of the canvas. I uploaded the Python code and an image which > demonstrates the problem. > > http://www.nabble.com/file/p26012393/ForUpload.py ForUpload.py > http://www.nabble.com/file/p26012393/DSC_1108.JPG DSC_1108.JPG > -- I don't see anything that's wrong with the images here, except that there's a 1- or 2- pixel gray border around the images. If this is what you mean, you can probably get rid of it by specifying bd=0, highlightthickness=0 in the Canvas constructors. HTH Michael From michael.odonnell at uam.es Thu Oct 22 23:07:57 2009 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Thu, 22 Oct 2009 23:07:57 +0200 Subject: [Tkinter-discuss] Grid Geometry Manager & ImageTk.PhotoImage In-Reply-To: <20091022222401.e5e670e8.klappnase@web.de> References: <26012393.post@talk.nabble.com> <20091022222401.e5e670e8.klappnase@web.de> Message-ID: <47e491110910221407o24ddf799if9bdd243a677f2ec@mail.gmail.com> Hi Michael, Francis, Michael, if you change the bg of the canvases, you will see that Francis is right, the canvas extends past the edge of the photo image. I changed his code as follows adding the bg atributes: panel1 = tk.Canvas(root, bg="red") panel1.grid(row=0, column=0, sticky=tk.NSEW) panel2 = tk.Canvas(root, bg="blue") Francis, this behaviour is all as expected. A canvas does not adjust its size to its contents (the jpg). It opens with a default size. What you probably want to do is resize the canvas once the jpg is drawn. For instance, add these lines (or some subset) at the end of openImage: panel1['height']=h panel1['width']=w panel2['height']=h panel2['width']=w Mick On Thu, Oct 22, 2009 at 10:24 PM, Michael Lange wrote: > Hi, > > On Thu, 22 Oct 2009 08:46:19 -0700 (PDT) > buckr02 wrote: > > (...) >> >> I am having trouble with the images, however, as they are being cut >> off (only part of the image is being shown). ?I am using Canvas >> objects to hold the images. >> >> I was able to throw in a few lines to fix most of the problems, but >> since it isn't perfect, I'd like to get to the bottom of it. ?The >> only noticeable problem left is that if you load a vertical picture, >> there is space left to the right of the image that is counted as part >> of the canvas. ?I uploaded the Python code and an image which >> demonstrates the problem. >> >> http://www.nabble.com/file/p26012393/ForUpload.py ForUpload.py >> http://www.nabble.com/file/p26012393/DSC_1108.JPG DSC_1108.JPG >> -- > > I don't see anything that's wrong with the images here, except that > there's a 1- or 2- pixel gray border around the images. If this is what > you mean, you can probably get rid of it by specifying > bd=0, highlightthickness=0 in the Canvas constructors. > > HTH > > Michael > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > From kd8atu at gmail.com Fri Oct 23 02:03:17 2009 From: kd8atu at gmail.com (Joe Veldhuis) Date: Thu, 22 Oct 2009 20:03:17 -0400 Subject: [Tkinter-discuss] Getting Tix to work on Win32? Message-ID: <20091022200317.b7f1b598.kd8atu@gmail.com> Hello to all! I'm working on a project that uses the Tix widgets pretty heavily (the tixGrid widgit is pretty much the centerpiece of the whole thing). It's going great on Linux, but now I need to get it running on Windows. The instructions for building Tix and its Python extension on Win32 are confusing and appear to be outdated, so can anyone who's done it recently tell me where to start? My Win32 dev machine is running WinXP-SP3 with Python 2.6.3 and Cygwin 1.7. MSVC is not installed at present but I have access to Visual Studio 2008 if I need it. Thanks, -Joe From klappnase at web.de Fri Oct 23 10:09:47 2009 From: klappnase at web.de (Michael Lange) Date: Fri, 23 Oct 2009 10:09:47 +0200 Subject: [Tkinter-discuss] Grid Geometry Manager & ImageTk.PhotoImage In-Reply-To: <47e491110910221407o24ddf799if9bdd243a677f2ec@mail.gmail.com> References: <26012393.post@talk.nabble.com> <20091022222401.e5e670e8.klappnase@web.de> <47e491110910221407o24ddf799if9bdd243a677f2ec@mail.gmail.com> Message-ID: <20091023100947.ec467eba.klappnase@web.de> Hi, On Thu, 22 Oct 2009 23:07:57 +0200 "Michael O'Donnell" wrote: > Hi Michael, Francis, > > Michael, if you change the bg of the canvases, you > will see that Francis is right, the canvas extends > past the edge of the photo image. That is exactly what I did, but I cannot confirm this behavior here (on debian linux, python-2.5.2, Tk-8.4.19), so maybe the exact behavior is different on different platforms / Tk-versions ? Michael From michael.odonnell at uam.es Fri Oct 23 10:23:22 2009 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Fri, 23 Oct 2009 10:23:22 +0200 Subject: [Tkinter-discuss] Grid Geometry Manager & ImageTk.PhotoImage In-Reply-To: <20091023100947.ec467eba.klappnase@web.de> References: <26012393.post@talk.nabble.com> <20091022222401.e5e670e8.klappnase@web.de> <47e491110910221407o24ddf799if9bdd243a677f2ec@mail.gmail.com> <20091023100947.ec467eba.klappnase@web.de> Message-ID: <47e491110910230123xdce0a6bt4c07e708f8223281@mail.gmail.com> Sorry, yes, I should have specified I am working under Windows, and was using python 2.5.4 with its default Tk. Which asked the question why you, a major Python/Tkinter user, have not upgraded to 2.6 let alone 3.1? (myself, I had problems with making standalone applications using py2exe under windows for Vista/Windows 7, so reverted to the one that worked, but that is not for a Tkinter list). Mick On Fri, Oct 23, 2009 at 10:09 AM, Michael Lange wrote: > Hi, > > On Thu, 22 Oct 2009 23:07:57 +0200 > "Michael O'Donnell" wrote: > >> Hi Michael, Francis, >> >> Michael, if you change the bg of the canvases, you >> will see that Francis is right, the canvas extends >> past the edge of the photo image. > > That is exactly what I did, but I cannot confirm this behavior here (on > debian linux, python-2.5.2, Tk-8.4.19), so maybe the exact behavior is > different on different platforms / Tk-versions ? > > Michael > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > From klappnase at web.de Fri Oct 23 17:06:59 2009 From: klappnase at web.de (Michael Lange) Date: Fri, 23 Oct 2009 17:06:59 +0200 Subject: [Tkinter-discuss] Grid Geometry Manager & ImageTk.PhotoImage In-Reply-To: <47e491110910230123xdce0a6bt4c07e708f8223281@mail.gmail.com> References: <26012393.post@talk.nabble.com> <20091022222401.e5e670e8.klappnase@web.de> <47e491110910221407o24ddf799if9bdd243a677f2ec@mail.gmail.com> <20091023100947.ec467eba.klappnase@web.de> <47e491110910230123xdce0a6bt4c07e708f8223281@mail.gmail.com> Message-ID: <20091023170659.5b7e4276.klappnase@web.de> Hi, On Fri, 23 Oct 2009 10:23:22 +0200 "Michael O'Donnell" wrote: > Sorry, yes, I should have specified I am working under Windows, > and was using python 2.5.4 with its default Tk. > > Which asked the question why you, a major Python/Tkinter user, > have not upgraded to 2.6 let alone 3.1? > > (myself, I had problems with making standalone applications > using py2exe under windows for Vista/Windows 7, so reverted > to the one that worked, but that is not for a Tkinter list). > > Mick > Now I got curious and installed both python-2.5.4 and python-2.6.3 on my old win2k box, and now I see what you mean. It has obviously nothing to do with tcl- or python-versions and I tried several window managers here under X and they all behave the same, so it seems to be a difference between windows and X. To solve this, it is surely the best to explicitely resize the canvas when loading an image. Michael From michael.odonnell at uam.es Mon Oct 26 11:22:58 2009 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Mon, 26 Oct 2009 11:22:58 +0100 Subject: [Tkinter-discuss] Need help on gui focus l In-Reply-To: <4AD5421B.3070000@gmail.com> References: <4AD5421B.3070000@gmail.com> Message-ID: <47e491110910260322l74d4490bp894f3d0a2a12e2d1@mail.gmail.com> Sorry for the slow reply, busy week last week. Replace Michael's filedialog function with the following: def filedialog(): oldFoc = top.focus_get() print tkFileDialog.askopenfilename() if oldFoc: oldFoc.focus_set() ...then you should have the behaviour you expect. (the 'if' is necessary in case their is no prior focus). At least on my Windows XP running Python 2.5.3 Mick On Wed, Oct 14, 2009 at 4:14 AM, BlackKnight wrote: > Hi folks, > > I am using Tkinter to do a simple GUI for my program. > > It contains A MainGui and A ChildGui: > A button on the MainGUI will popout the childgui. > On the childgui there is a browse button which popout a dialog to allow > user to browser and choose a file. > > I have no problem at doing them. > > The problem is after the uesr choose a file the focus will return to the > MainGui intead of the childgui. The child gui just go hide behind the Main. > > I've tried focus_set, focus_force but none of them seem work. > > I did some research but found nothing working. It's not a big problem, > but is really really annoying. > (Actually I notice the examples from some python book I am reading has > the exact same problem. The author even tried to spawn the child gui > away from the main one, so when the focus return from the browse dialog > , the maingui won't block the child one~~ Is that how tkinter should work?) > > Any suggestions? > > Thanks in advance~~ > > > Frank > > > > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > From ethoms at usgs.gov Fri Oct 30 21:46:35 2009 From: ethoms at usgs.gov (ethoms) Date: Fri, 30 Oct 2009 13:46:35 -0700 (PDT) Subject: [Tkinter-discuss] getvalue fails on pmw.radioselect after using configure on component Message-ID: <26136605.post@talk.nabble.com> I am using a generic function to build Pmw.RadioSelect widgets: def make_checkbuttons(self, parent, buttonlist): """Make a multiple-selection Pmw.RadioSelect checkbuttons""" widget = Pmw.RadioSelect(parent, selectmode = 'multiple', buttontype = 'checkbutton', orient = 'vertical') widget.pack(side = 'left', expand = True, fill = 'both', padx = 4) for button in buttonlist: widget.add(button) return widget In one instance I want to configure the options on three checkboxes after the generic creation of the widget: #after the generic construction of this radio button group, #we need to set some specific parameters self.var1 = IntVar() self.var4 = IntVar() self.generalops.button('all maps same data frame').configure(state = 'disabled', padx = 15) self.generalops.button('leave ArcMap open').configure(command = self.leave_open, variable = self.var1) self.generalops.button('export plots').configure(command = self.export_plots, variable = self.var4) #doesn't matter if I pack before or after the post-configuration self.generalops.pack(side = 'left', anchor = 'w') But, if I do that, self.generalops.getvalue() returns nothing for those buttons which have been post-configured. Any suggestions? -- View this message in context: http://old.nabble.com/getvalue-fails-on-pmw.radioselect-after-using-configure-on-component-tp26136605p26136605.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From ethoms at usgs.gov Fri Oct 30 22:13:48 2009 From: ethoms at usgs.gov (ethoms) Date: Fri, 30 Oct 2009 14:13:48 -0700 (PDT) Subject: [Tkinter-discuss] getvalue fails on pmw.radioselect after using configure on component In-Reply-To: <26136605.post@talk.nabble.com> References: <26136605.post@talk.nabble.com> Message-ID: <26136945.post@talk.nabble.com> No, wait, it has something to do with assigning a command (or a variable) to the button. Those two buttons never show up in the list. Apologies for not checking that first. ethoms wrote: > > I am using a generic function to build Pmw.RadioSelect widgets: > > def make_checkbuttons(self, parent, buttonlist): > """Make a multiple-selection Pmw.RadioSelect checkbuttons""" > widget = Pmw.RadioSelect(parent, > selectmode = 'multiple', > buttontype = 'checkbutton', > orient = 'vertical') > widget.pack(side = 'left', expand = True, fill = 'both', padx = 4) > for button in buttonlist: > widget.add(button) > return widget > > In one instance I want to configure the options on three checkboxes after > the generic creation of the widget: > > #after the generic construction of this radio button group, > #we need to set some specific parameters > self.var1 = IntVar() > self.var4 = IntVar() > self.generalops.button('all maps same data frame').configure(state > = 'disabled', padx = 15) > self.generalops.button('leave ArcMap open').configure(command = > self.leave_open, variable = self.var1) > self.generalops.button('export plots').configure(command = > self.export_plots, variable = self.var4) > > #doesn't matter if I pack before or after the post-configuration > self.generalops.pack(side = 'left', anchor = 'w') > > But, if I do that, self.generalops.getvalue() returns nothing for those > buttons which have been post-configured. Any suggestions? > -- View this message in context: http://old.nabble.com/getvalue-fails-on-pmw.radioselect-after-using-configure-on-component-tp26136605p26136945.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.