From matt.keenan at oracle.com Tue Mar 1 17:05:21 2011 From: matt.keenan at oracle.com (Matt Keenan) Date: Tue, 01 Mar 2011 16:05:21 +0000 Subject: [Tkinter-discuss] Generating Postscript from canvas whilst hidden Message-ID: <4D6D1941.60506@oracle.com> Hi, Looking for the best means of generating postscript from a canvas widget but having the canvas widget in the background, and not visible to the user. I have an application that I'd like to batch generate a web site from, including a set of graphs. the graphs are plotted on a canvas widget with a convenience function and then postscript is generated using the canvas.postscript() method. The only means I can see of generating valid postscript is when the canvas widget and root are displayed to the user. I'd prefer if this could be hidden. Following code is a rough example of what happens when the user clicks the generate button def generate_webpage(self, emplist): myroot = Tk() mycanvas = Canvas(myroot, width=700, height=400) mycanvas.pack() mycanvas.root = myroot for i in range(0, len(emplist)): # PostScript file name psname = "graph%s.ps" % (i) # Clear canvas down canvas.delete(ALL) # Plot graph on canvas PlotLineGraph(mycanvas, emplist[i]) # Update tasks and canvas self.update_idletasks() mycanvas.update() mycanvas.update_idletasks() # Generate postscript mycanvas.postscript(file=psname, pagewidth=675, pageheight=400) myroot.destroy() As can be seen, when generate_webpage is clicked, a new popup window is shown and each graph as generated is shown within the window as it's done. If I add myroot.withdraw() to above method, just after packing mycanvas, then no popup appears but all the postsript files are blank nothing is actually plotted on the canvas !! Does anyone know of a way to get around this ? cheers Matt From igor.e.novikov at gmail.com Wed Mar 2 02:15:34 2011 From: igor.e.novikov at gmail.com (Igor Novikov) Date: Wed, 2 Mar 2011 03:15:34 +0200 Subject: [Tkinter-discuss] Generating Postscript from canvas whilst hidden In-Reply-To: <4D6D1941.60506@oracle.com> References: <4D6D1941.60506@oracle.com> Message-ID: You can try using pycairo to generate PS/PDF/PNG in the background. http://cairographics.org/pycairo/ http://www.tortall.net/mu/wiki/CairoTutorial I think this will be better way than widget tricks. -- Regards, Igor Novikov sK1 Project http://sk1project.org On Tue, Mar 1, 2011 at 6:05 PM, Matt Keenan wrote: > Hi, > > Looking for the best means of generating postscript from a canvas widget > but having the canvas widget in the background, and not visible to the user. > > I have an application that I'd like to batch generate a web site from, > including a set of graphs. > > the graphs are plotted on a canvas widget with a convenience function and > then postscript is generated using the canvas.postscript() method. > > The only means I can see of generating valid postscript is when the canvas > widget and root are displayed to the user. I'd prefer if this could be > hidden. > > Following code is a rough example of what happens when the user clicks the > generate button > > def generate_webpage(self, emplist): > myroot = Tk() > mycanvas = Canvas(myroot, width=700, height=400) > mycanvas.pack() > mycanvas.root = myroot > > for i in range(0, len(emplist)): > # PostScript file name > psname = "graph%s.ps" % (i) > > # Clear canvas down > canvas.delete(ALL) > > # Plot graph on canvas > PlotLineGraph(mycanvas, emplist[i]) > > # Update tasks and canvas > self.update_idletasks() > mycanvas.update() > mycanvas.update_idletasks() > > # Generate postscript > mycanvas.postscript(file=psname, pagewidth=675, > pageheight=400) > > myroot.destroy() > > > As can be seen, when generate_webpage is clicked, a new popup window is > shown and each graph as generated is shown within the window as it's done. > > If I add myroot.withdraw() to above method, just after packing mycanvas, > then no popup appears but all the postsript files are blank > nothing is actually plotted on the canvas !! > > Does anyone know of a way to get around this ? > > cheers > > Matt > > > _______________________________________________ > 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 suffii at gmail.com Thu Mar 3 02:23:59 2011 From: suffii at gmail.com (Behseini) Date: Wed, 2 Mar 2011 17:23:59 -0800 (PST) Subject: [Tkinter-discuss] How to Handle Selected Item Event of ListBox Message-ID: <31055478.post@talk.nabble.com> Hi, Gribouillis, helped me to understand how to invoke a function by btn click event handler, at my last post.Now I am trying to understand how I can handle an selected item event from a list box? lets say I have a list box like below and I want to call a method to change the frame background color based on which item has been selected from Tkinter import * class App: def __init__(self, parent): self.myParent = parent self.fm = Frame(parent) self.fm.pack_propagate(0) self.fm.pack() self.Lb1 = Listbox(self.fm,height=4, width=15,selectbackground="orange") self.Lb1.insert(1, "Red") self.Lb1.insert(2, "Green") self.Lb1.insert(3, "Blue") self.Lb1.pack() def make_Red(self): self.fm.configure(bg="RED") def make_Blue(self): self.fm.configure(bg="BLUE") def make_Green(self): self.fm.configure(bg="GREEN") root = Tk() root.title ("Color Option") root.geometry("%dx%d%+d%+d" % (300, 200, 0, 0)) app = App(root) root.mainloop() can you please take a look at this code and let me know how I can call one of the method by selecting the item from the list? Thanks -- View this message in context: http://old.nabble.com/How-to-Handle-Selected-Item-Event-of-ListBox-tp31055478p31055478.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From klappnase at web.de Thu Mar 3 22:44:12 2011 From: klappnase at web.de (Michael Lange) Date: Thu, 3 Mar 2011 22:44:12 +0100 Subject: [Tkinter-discuss] How to Handle Selected Item Event of ListBox In-Reply-To: <31055478.post@talk.nabble.com> References: <31055478.post@talk.nabble.com> Message-ID: <20110303224412.1ab45fad.klappnase@web.de> Hi Behseini , Thus spoketh Behseini unto us on Wed, 2 Mar 2011 17:23:59 -0800 (PST): (...) > > can you please take a look at this code and let me know how I can call > one of the method by selecting the item from the list? You will want to have a look at the Listbox widget's <>' virtual event, which is generated each time the selection changes (see the listbox Tk man page for details). A brief usage example: ######################################### from Tkinter import * root = Tk() l = Listbox(root, selectmode='multiple') l.pack() def on_select(event): print event.widget.curselection() l.bind('<>', on_select) for i in range(10): l.insert('end', 'Item %d' % i) root.mainloop() ######################################### I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. No one may kill a man. Not for any purpose. It cannot be condoned. -- Kirk, "Spock's Brain", stardate 5431.6 From suffii at gmail.com Fri Mar 4 00:22:06 2011 From: suffii at gmail.com (Behseini) Date: Thu, 3 Mar 2011 15:22:06 -0800 (PST) Subject: [Tkinter-discuss] How to Handle Selected Item Event of ListBox In-Reply-To: <20110303224412.1ab45fad.klappnase@web.de> References: <31055478.post@talk.nabble.com> <20110303224412.1ab45fad.klappnase@web.de> Message-ID: <31063738.post@talk.nabble.com> Thanks Michael But in this issue I have to have a if clause to select from the user chose some thing like self.zones = self.Lb1.curselection() if self.zones == 1: command=self.make_Red() if self.zones == 2: command=self.make_Red() if self.zones == 3: command=self.make_Red() But i can/t figure it out how to set it up Thanks for your time again No one may kill a man. Not for any purpose. It cannot be condoned. -- Kirk, "Spock's Brain", stardate 5431.6 _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss -- View this message in context: http://old.nabble.com/How-to-Handle-Selected-Item-Event-of-ListBox-tp31055478p31063738.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From klappnase at web.de Fri Mar 4 10:41:31 2011 From: klappnase at web.de (Michael Lange) Date: Fri, 4 Mar 2011 10:41:31 +0100 Subject: [Tkinter-discuss] How to Handle Selected Item Event of ListBox In-Reply-To: <31063738.post@talk.nabble.com> References: <31055478.post@talk.nabble.com> <20110303224412.1ab45fad.klappnase@web.de> <31063738.post@talk.nabble.com> Message-ID: <20110304104131.4b7a5341.klappnase@web.de> Hi, Thus spoketh Behseini unto us on Thu, 3 Mar 2011 15:22:06 -0800 (PST): > > Thanks Michael > But in this issue I have to have a if clause to select from the user > chose some thing like > self.zones = self.Lb1.curselection() > if self.zones == 1: > command=self.make_Red() > if self.zones == 2: > command=self.make_Red() > if self.zones == 3: > command=self.make_Red() > > But i can/t figure it out how to set it up > Thanks for your time again > sorry, i thought this was obvious ;) You simply need to change the ListboxSelect callback from my example into something like: def on_select(event): sel = event.widget.curselection() if sel[0] == 1: do_this() elif sel[0] == 2: do_that() .... I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Compassion -- that's the one things no machine ever had. Maybe it's the one thing that keeps men ahead of them. -- McCoy, "The Ultimate Computer", stardate 4731.3 From mario.stg at videotron.ca Sat Mar 19 16:58:16 2011 From: mario.stg at videotron.ca (Mario St-Gelais) Date: Sat, 19 Mar 2011 11:58:16 -0400 Subject: [Tkinter-discuss] Notebook - Bad Window Path Name Message-ID: <20110319115816.4918a35f@xeon.astj-outaouais.com> Good Day All. I am trying to get Notebook to work and the following code return errors. If I replace f2 with something similar to f1, it works. Thanks. Code is: from tkinter import * from tkinter import ttk class ClientNoteBook(): def __init__(self, root): self.root=root nb=ttk.Notebook(root) f1=Frame(nb) f2=FirstFrame(nb) nb.add(f1, text='info') nb.add(f2, text='in') nb.pack() def PlaceClientInfo(self): pass class FirstFrame(): def __init__(self,root): self.root=root self.frame=Frame(self.root) self.PlaceButtonCheck() def PlaceButtonCheck(self): self.btn=ttk.Button(self.root,text='Open Child',command=self.DebugThis) self.btn.grid(column=0,row=1) def DebugThis(self): print('rrrrrr') if __name__=='__main__': root = Tk() root.option_add('*font', ('verdana', 9, 'normal')) root.title("Information Client") display = ClientNoteBook(root) root.mainloop() Error returned is: Traceback (most recent call last): File "/tmp/clientnotebook.py", line 31, in display = ClientNoteBook(root) File "/tmp/clientnotebook.py", line 11, in __init__ nb.add(f2, text='in') File "/usr/lib/python3.2/tkinter/ttk.py", line 865, in add self.tk.call(self._w, "add", child, *(_format_optdict(kw))) _tkinter.TclError: bad window path name "<__main__.FirstFrame object at 0x7f556e74dcd0>" From klappnase at web.de Sat Mar 19 18:37:07 2011 From: klappnase at web.de (Michael Lange) Date: Sat, 19 Mar 2011 18:37:07 +0100 Subject: [Tkinter-discuss] Notebook - Bad Window Path Name In-Reply-To: <20110319115816.4918a35f@xeon.astj-outaouais.com> References: <20110319115816.4918a35f@xeon.astj-outaouais.com> Message-ID: <20110319183707.b7216d95.klappnase@web.de> Hi Mario, Thus spoketh Mario St-Gelais unto us on Sat, 19 Mar 2011 11:58:16 -0400: > Good Day All. > > I am trying to get Notebook to work and the following code return > errors. If I replace f2 with something similar to f1, it works. > The problem is the following class definition: > > class FirstFrame(): > def __init__(self,root): > self.root=root > self.frame=Frame(self.root) > self.PlaceButtonCheck() (...) According to this, an instance of the FirstFrame class is *not* a tk widget, but just a generic python object. So you will have to * either replace the following lines in your code: f2=FirstFrame(nb) nb.add(f2, text='in') with f2=FirstFrame(nb) nb.add(f2.frame, text='in')# pass the Frame object to nb.add() * or (better) change your class definition so that the FirstFrame instance becomes a real Frame object by subclassing Frame. The usual way to do this is something like: class FirstFrame(Frame): def __init__(self, *args, **kw): Frame.__init__(self, *args, **kw) self.PlaceButtonCheck() ...(etc.)... (note that you don't need the self.root attribute any longer, because every widget has its parent linked to self.master by default). I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. I'm frequently appalled by the low regard you Earthmen have for life. -- Spock, "The Galileo Seven", stardate 2822.3 From mario.stg at videotron.ca Sun Mar 20 13:45:33 2011 From: mario.stg at videotron.ca (Mario St-Gelais) Date: Sun, 20 Mar 2011 08:45:33 -0400 Subject: [Tkinter-discuss] Notebook - Bad Window Path Name In-Reply-To: <20110319183707.b7216d95.klappnase@web.de> References: <20110319115816.4918a35f@xeon.astj-outaouais.com> <20110319183707.b7216d95.klappnase@web.de> Message-ID: <20110320084533.19a3a14c@xeon.astj-outaouais.com> Thanks. This is an answer on a silver plate. :) Thanks for the self.root tip too. That definitely did the trick. I went with your option two. Mario On Sat, 19 Mar 2011 18:37:07 +0100 Michael Lange wrote: > Hi Mario, > > Thus spoketh Mario St-Gelais > unto us on Sat, 19 Mar 2011 11:58:16 -0400: > > > Good Day All. > > > > I am trying to get Notebook to work and the following code return > > errors. If I replace f2 with something similar to f1, it works. > > > > The problem is the following class definition: > > > > > class FirstFrame(): > > def __init__(self,root): > > self.root=root > > self.frame=Frame(self.root) > > self.PlaceButtonCheck() > (...) > > According to this, an instance of the FirstFrame class is *not* a tk > widget, but just a generic python object. So you will have to > > * either replace the following lines in your code: > > f2=FirstFrame(nb) > nb.add(f2, text='in') > > with > > f2=FirstFrame(nb) > nb.add(f2.frame, text='in')# pass the Frame object to nb.add() > > * or (better) change your class definition so that the FirstFrame > instance becomes a real Frame object by subclassing Frame. The > usual way to do this is something like: > > class FirstFrame(Frame): > def __init__(self, *args, **kw): > Frame.__init__(self, *args, **kw) > self.PlaceButtonCheck() > ...(etc.)... > > (note that you don't need the self.root attribute any longer, because > every widget has its parent linked to self.master by default). > > I hope this helps > > Michael > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. > --- ... .--. . .-. > > I'm frequently appalled by the low regard you Earthmen have for life. > -- Spock, "The Galileo Seven", stardate 2822.3 > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss From kevin.buchs at gmail.com Mon Mar 21 21:45:40 2011 From: kevin.buchs at gmail.com (Kevin Buchs) Date: Mon, 21 Mar 2011 15:45:40 -0500 Subject: [Tkinter-discuss] want to build Python with Tkinter on Linux Message-ID: I have locked-down (by others) Linux systems, so I need my own custom install of Python (2.7). I have yet to get Tkinter working in the build process. Python will be in a non-standard location and Tcl/Tk are in a non-standard location. I get these messages from a "make": $ make running build running build_ext building dbm using gdbm INFO: Can't locate Tcl/Tk libs and/or headers Python build finished, but the necessary bits to build these modules were not found: _tkinter bsddb185 dl imageop sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. running build_scripts Do there exist any build instructions to direct me as to how to fix this? I am not seeing anything in configure. -- Kevin Buchs -------------- next part -------------- An HTML attachment was scrubbed... URL: From timj at tolisgroup.com Mon Mar 21 22:14:21 2011 From: timj at tolisgroup.com (Tim Jones) Date: Mon, 21 Mar 2011 14:14:21 -0700 Subject: [Tkinter-discuss] want to build Python with Tkinter on Linux In-Reply-To: References: Message-ID: <25EA60CF-8A25-4E16-BD06-E503ECD49304@tolisgroup.com> On Mar 21, 2011, at 1:45 PM, Kevin Buchs wrote: > I have locked-down (by others) Linux systems, so I need my own custom install of Python (2.7). I have yet to get Tkinter working in the build process. Python will be in a non-standard location and Tcl/Tk are in a non-standard location. I get these messages from a "make": > > $ make > running build > running build_ext > building dbm using gdbm > INFO: Can't locate Tcl/Tk libs and/or headers > > Python build finished, but the necessary bits to build these modules were not found: > _tkinter bsddb185 dl > imageop sunaudiodev > To find the necessary bits, look in setup.py in detect_modules() for the module's name. > > running build_scripts > > Do there exist any build instructions to direct me as to how to fix this? I am not seeing anything in configure. I use custom locations all the time - have you tried the "--prefix=" setting for configure? ./configure --prefix=/home/secureuser/ That would put everything into /home/secureuser/lib/ and /home/secureuser/bin/. Just be aware that all of the peojects need the same prefix setting. Tim -------------- next part -------------- An HTML attachment was scrubbed... URL: From kevin.buchs at gmail.com Mon Mar 21 22:42:24 2011 From: kevin.buchs at gmail.com (Kevin Buchs) Date: Mon, 21 Mar 2011 16:42:24 -0500 Subject: [Tkinter-discuss] want to build Python with Tkinter on Linux In-Reply-To: <25EA60CF-8A25-4E16-BD06-E503ECD49304@tolisgroup.com> References: <25EA60CF-8A25-4E16-BD06-E503ECD49304@tolisgroup.com> Message-ID: Tim, Thanks for your reply. This will handle the Python install path. But I can't get Python to build with Tkinter. - Kevin Buchs On Mon, Mar 21, 2011 at 4:14 PM, Tim Jones wrote: > I use custom locations all the time - have you tried the "--prefix=" > setting for configure? > > ./configure --prefix=/home/secureuser/ > > That would put everything into /home/secureuser/lib/ and > /home/secureuser/bin/. Just be aware that all of the peojects need the same > prefix setting. > > Tim > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From timj at tolisgroup.com Mon Mar 21 23:25:41 2011 From: timj at tolisgroup.com (Tim Jones) Date: Mon, 21 Mar 2011 15:25:41 -0700 Subject: [Tkinter-discuss] want to build Python with Tkinter on Linux In-Reply-To: References: <25EA60CF-8A25-4E16-BD06-E503ECD49304@tolisgroup.com> Message-ID: As I mentioned, you would need to provide the same --prefix for the TCL/TK build as well. I build in this order: tcl tk expect python They are all built with "configure --prefix=/home/secureuser" (secureuser is a sandbox user on my systems). Tim On Mar 21, 2011, at 2:42 PM, Kevin Buchs wrote: > Tim, > > Thanks for your reply. This will handle the Python install path. But I can't get Python to build with Tkinter. > > - Kevin Buchs > > On Mon, Mar 21, 2011 at 4:14 PM, Tim Jones wrote: > I use custom locations all the time - have you tried the "--prefix=" setting for configure? > > ./configure --prefix=/home/secureuser/ > > That would put everything into /home/secureuser/lib/ and /home/secureuser/bin/. Just be aware that all of the peojects need the same prefix setting. > > Tim > -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Tue Mar 22 12:12:31 2011 From: klappnase at web.de (Michael Lange) Date: Tue, 22 Mar 2011 12:12:31 +0100 Subject: [Tkinter-discuss] want to build Python with Tkinter on Linux In-Reply-To: References: Message-ID: <20110322121231.0f2cfb45.klappnase@web.de> Hi Kevin, Thus spoketh Kevin Buchs unto us on Mon, 21 Mar 2011 15:45:40 -0500: > I have locked-down (by others) Linux systems, so I need my own custom > install of Python (2.7). I have yet to get Tkinter working in the build > process. Python will be in a non-standard location and Tcl/Tk are in a > non-standard location. I get these messages from a "make": > > $ make > running build > running build_ext > building dbm using gdbm > INFO: Can't locate Tcl/Tk libs and/or headers Have you tried to call $ export LD_LIBRARY_PATH=/usr/local/lib before ./configure (of course with your actual "tcl-lib-path" instead of /usr/local/lib)? At least here (debian lenny) this helps, I think it is even documented somewhere, although I can't remember where ;) Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Intuition, however illogical, is recognized as a command prerogative. -- Kirk, "Obsession", stardate 3620.7 From kevin.buchs at gmail.com Tue Mar 22 17:25:53 2011 From: kevin.buchs at gmail.com (Kevin Buchs) Date: Tue, 22 Mar 2011 11:25:53 -0500 Subject: [Tkinter-discuss] want to build Python with Tkinter on Linux In-Reply-To: <20110322121231.0f2cfb45.klappnase@web.de> References: <20110322121231.0f2cfb45.klappnase@web.de> Message-ID: Hey! It works great, incorporating both hints. Thanks, guys. -- Kevin Buchs -------------- next part -------------- An HTML attachment was scrubbed... URL: From spooky.ln at tbs-software.com Sun Mar 27 12:43:06 2011 From: spooky.ln at tbs-software.com (Martin B.) Date: Sun, 27 Mar 2011 12:43:06 +0200 Subject: [Tkinter-discuss] Tkinter Canvas MouseWheel problem. Message-ID: <4D8F14BA.5050605@tbs-software.com> hi all, maybe this is stupid question but i cannot catch mousewheel event in Tk.Canvas. I tryied , , <4> but without any luck. <1>, <2>, <3> working. I'm on Win7 Python3.2. here is my example. Is something wrong in code or i need some magic to catch this event. thanks. #encoding: utf-8 from tkinter import * import tkinter.ttk as ttk from PIL import Image, ImageTk class PhotoView(Canvas): def __init__(self, parent, **kw): self.frame = Frame(parent, bd=2, relief='sunken') self.frame.rowconfigure(0, weight=1) self.frame.columnconfigure(0, weight=1) super().__init__(self.frame) Canvas.grid(self, column=0, row=0, sticky='news') xscroll = ttk.Scrollbar(self.frame, orient=HORIZONTAL) xscroll.grid(column=0, row=1, sticky='we') yscroll = ttk.Scrollbar(self.frame, orient=VERTICAL) yscroll.grid(column=1, row=0, sticky='sn') self.config(width=640, height=480, xscrollcommand=xscroll.set, yscrollcommand=yscroll.set) xscroll.config(command=self.xview) yscroll.config(command=self.yview) # reset coordinate system self.xview_moveto(0) self.yview_moveto(0) # binding self.bind('', self.make_scroll) self.bind('', self.drag_image) self.bind('', self.zoom_image) # dont work self.bind('', self.zoom_image) # dont work self.focus() def drag_image(self, event=None): pass def make_scroll(self, event=None): self.config(scrollregion=self.bbox(ALL)) def zoom_image(self, event=None): print(event) def grid(self, **kw): self.frame.grid(**kw) def pack(self, **kw): self.frame.pack(**kw) class mainGui(Tk): def __init__(self): super().__init__() im = ImageTk.PhotoImage(Image.open('test_img.jpg')) c = PhotoView(self) c.pack(fill='both', expand='yes') c.create_image(0, 0, image=im, anchor='nw') c.image = im # keep reference !! if __name__ == '__main__': app = mainGui() app.mainloop() From spooky.ln at tbs-software.com Sun Mar 27 13:51:36 2011 From: spooky.ln at tbs-software.com (Martin B.) Date: Sun, 27 Mar 2011 13:51:36 +0200 Subject: [Tkinter-discuss] Tkinter Canvas MouseWheel problem. In-Reply-To: <4D8F14BA.5050605@tbs-software.com> References: <4D8F14BA.5050605@tbs-software.com> Message-ID: <4D8F24C8.1090005@tbs-software.com> Ok. Solved grabs only parent widget [here Tk]. source edited as parent.bind().