From bob at passcal.nmt.edu Tue Sep 1 20:07:45 2009 From: bob at passcal.nmt.edu (Bob Greschke) Date: Tue, 1 Sep 2009 12:07:45 -0600 Subject: [Tkinter-discuss] Canvas tag bindings not going away? Message-ID: <44280719-37A2-4467-84B5-656167602D39@passcal.nmt.edu> Doesn't ACanvas.delete(ALL) get rid of bindings too? I'm drawing regular map dots (create_oval) on a Canvas "map" and each one gets a Tag, like "P1", "P2", etc. I do a tag_bind to to get a popup menu item for each dot. Everything works fine. I then have two radiobuttons, one for a regular map (described above), and one for drawing the dots a different color depending on elevation. When the Redraw button is hit with the elevation map mode selected the canvas gets cleared, the background color gets changed, a .delete(ALL) is done (and a .find_all() returns ()), I redraw the create_oval()s with the same kind of Tags ("P1", "P2", etc.), but without doing a tag_bind to (same bunch of code, just with an if-statement to control which kind of dot gets drawn). The new dots still react to a event like as if the TAG is still bound to the event. If I start all over, but draw the elevation map first then the dots don't do the popup menu. If I then redraw with the normal map option the popup menu bind gets bound to the dots from that point on. Do I have to loop through all of the items and delete the tags before doing the .delete(ALL) or something? This could be major. I use a lot of Tags and binds on a lot of Canvases, but I've never noticed this before. It's doing this on several OSs and versions of everything, so it must be me. Thanks! Bob From klappnase at web.de Tue Sep 1 20:57:51 2009 From: klappnase at web.de (Michael Lange) Date: Tue, 1 Sep 2009 20:57:51 +0200 Subject: [Tkinter-discuss] Canvas tag bindings not going away? In-Reply-To: <44280719-37A2-4467-84B5-656167602D39@passcal.nmt.edu> References: <44280719-37A2-4467-84B5-656167602D39@passcal.nmt.edu> Message-ID: <20090901205751.9b670dde.klappnase@web.de> Hi Bob, On Tue, 1 Sep 2009 12:07:45 -0600 Bob Greschke wrote: > Doesn't ACanvas.delete(ALL) get rid of bindings too? I'm drawing > regular map dots (create_oval) on a Canvas "map" and each one gets a > Tag, like "P1", "P2", etc. I do a tag_bind to to get a > popup menu item for each dot. Everything works fine. > > I then have two radiobuttons, one for a regular map (described > above), and one for drawing the dots a different color depending on > elevation. When the Redraw button is hit with the elevation map > mode selected the canvas gets cleared, the background color gets > changed, a .delete(ALL) is done (and a .find_all() returns ()), I > redraw the create_oval()s with the same kind of Tags ("P1", "P2", > etc.), but without doing a tag_bind to (same bunch of > code, just with an if-statement to control which kind of dot gets > drawn). The new dots still react to a event like as if > the TAG is still bound to the event. If I start all over, > but draw the elevation map first then the dots don't do the popup > menu. If I then redraw with the normal map option the popup menu > bind gets bound to the dots from that point on. > > Do I have to loop through all of the items and delete the tags > before doing the .delete(ALL) or something? This could be major. I > use a lot of Tags and binds on a lot of Canvases, but I've never > noticed this before. It's doing this on several OSs and versions of > everything, so it must be me. > > Thanks! > > Bob > If I understand you correctly, what you describe is what I think that tag bindings are supposed to do. I tried the following: >>> from Tkinter import * >>> c = Canvas() >>> c.pack() >>> def test(ev): ... print 'foo' ... >>> c.tag_bind('tag_foo', '<1>', test) >>> c.create_rectangle(0, 0, 100, 100, fill='blue', tags=('tag_foo')) 1 >>> foo foo foo foo The "foo"s at the end of the snippet are of course from clicking the blue rectangle. The point here is, that the tag-binding is obviously active without any items being created, and I believe that is exactly what it is for; if you want the binding to be removed when the item is deleted, you should bind to the item-id instead, or maybe use tag_unbind() to remove the bindings. I hope this helps Michael From bob at passcal.nmt.edu Tue Sep 1 22:08:42 2009 From: bob at passcal.nmt.edu (Bob Greschke) Date: Tue, 1 Sep 2009 14:08:42 -0600 Subject: [Tkinter-discuss] Canvas tag bindings not going away? In-Reply-To: <20090901205751.9b670dde.klappnase@web.de> References: <44280719-37A2-4467-84B5-656167602D39@passcal.nmt.edu> <20090901205751.9b670dde.klappnase@web.de> Message-ID: <2E7330A9-FDAB-4D1B-9391-394FFA63DB1D@passcal.nmt.edu> > If I understand you correctly, what you describe is what I think that > tag bindings are supposed to do. I tried the following: > >>>> from Tkinter import * >>>> c = Canvas() >>>> c.pack() >>>> def test(ev): > ... print 'foo' > ... >>>> c.tag_bind('tag_foo', '<1>', test) >>>> c.create_rectangle(0, 0, 100, 100, fill='blue', tags=('tag_foo')) > 1 >>>> foo > foo > foo > foo > > The "foo"s at the end of the snippet are of course from clicking the > blue rectangle. The point here is, that the tag-binding is obviously > active without any items being created, and I believe that is exactly > what it is for; if you want the binding to be removed when the item is > deleted, you should bind to the item-id instead, or maybe use > tag_unbind() to remove the bindings. > > I hope this helps > > Michael You are too smart. I've only been goofing with this stuff for about 7 years. Looking through my code I now understand that I didn't know anything. :) I've been binding to the tag in some places and to the "ID" of the create_x item in others. NOW I get it! That's exactly what was going on. A big thanks! Bob From greg.ewing at canterbury.ac.nz Wed Sep 2 00:23:19 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 02 Sep 2009 10:23:19 +1200 Subject: [Tkinter-discuss] Canvas tag bindings not going away? In-Reply-To: <44280719-37A2-4467-84B5-656167602D39@passcal.nmt.edu> References: <44280719-37A2-4467-84B5-656167602D39@passcal.nmt.edu> Message-ID: <4A9D9ED7.3020604@canterbury.ac.nz> Bob Greschke wrote: > I redraw the create_oval()s > with the same kind of Tags ("P1", "P2", etc.), but without doing a > tag_bind to ... The new dots still react to > a event like as if the TAG is still bound to the > event. It probably is. You've told the canvas " on any item tagged with "P3" does this", and haven't rescinded that instruction. In other words, the tag bindings are associated with the canvas itself, not the individual items. It sounds like you will indeed have to undo the tag bindings explicitly. Alternatively, come up with a tagging scheme that allows you to re-use the same tags for the same bindings, instead of inventing a new tag for each canvas item that you want to bind an event to. -- Greg From supersimha at gmail.com Wed Sep 2 18:33:43 2009 From: supersimha at gmail.com (simha) Date: Wed, 2 Sep 2009 09:33:43 -0700 (PDT) Subject: [Tkinter-discuss] Draw a table in Python 3.1 Message-ID: <25261023.post@talk.nabble.com> Hi all. I am very new to the world of python. I am desining a GUI using the tkinter module and would like to include a table of 6 columns and n rows. I am developing this code in windows xp. I downloaded a tktable module. But not able to install this. Please help me in this regard. Thanks in advance -- View this message in context: http://www.nabble.com/Draw-a-table-in-Python-3.1-tp25261023p25261023.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From peter.milliken at gmail.com Fri Sep 4 00:42:18 2009 From: peter.milliken at gmail.com (Peter Milliken) Date: Fri, 4 Sep 2009 08:42:18 +1000 Subject: [Tkinter-discuss] Draw a table in Python 3.1 In-Reply-To: <25261023.post@talk.nabble.com> References: <25261023.post@talk.nabble.com> Message-ID: <791153ba0909031542r7ed06bdetb13251f6303c576f@mail.gmail.com> So what was the problem? I am assuming you are referring to the tktable available from http://tktable.sourceforge.net/? Peter On Thu, Sep 3, 2009 at 2:33 AM, simha wrote: > > Hi all. I am very new to the world of python. I am desining a GUI using the > tkinter module and would like to include a table of 6 columns and n rows. I > am developing this code in windows xp. I downloaded a tktable module. But > not able to install this. Please help me in this regard. Thanks in advance > -- > View this message in context: > http://www.nabble.com/Draw-a-table-in-Python-3.1-tp25261023p25261023.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 peter.milliken at gmail.com Fri Sep 4 01:13:28 2009 From: peter.milliken at gmail.com (Peter Milliken) Date: Fri, 4 Sep 2009 09:13:28 +1000 Subject: [Tkinter-discuss] Draw a table in Python 3.1 In-Reply-To: <791153ba0909031542r7ed06bdetb13251f6303c576f@mail.gmail.com> References: <25261023.post@talk.nabble.com> <791153ba0909031542r7ed06bdetb13251f6303c576f@mail.gmail.com> Message-ID: <791153ba0909031613h3a0b06s625b1ca8b0caf4f9@mail.gmail.com> BTW, I have been looking at the Tktable from that source and it doesn't look like a straightforward process at all! Despite the fact the author of README.txt claims you can build it with cygwin if TEA is installed (not really clear what TEA is although I found a web-page, but the configure script tells me I have it installed on my system :-)), I certainly can't! If you then try and go down the route of using Visual Studio then you run into having to have Tcl8.4 installed - which I don't and since Tcl appears to be up to 8.5 and 8.6 makes it even harder! So I would suggest that you contact the folk at the sourceforge project and ask somebody to email you a pre-built windows set of binaries (and ask them to work a bit harder on getting their Windows/cygwin port working :-)). Peter On Fri, Sep 4, 2009 at 8:42 AM, Peter Milliken wrote: > So what was the problem? > I am assuming you are referring to the tktable available from > http://tktable.sourceforge.net/? > Peter > > > On Thu, Sep 3, 2009 at 2:33 AM, simha wrote: > >> >> Hi all. I am very new to the world of python. I am desining a GUI using >> the >> tkinter module and would like to include a table of 6 columns and n rows. >> I >> am developing this code in windows xp. I downloaded a tktable module. But >> not able to install this. Please help me in this regard. Thanks in advance >> -- >> View this message in context: >> http://www.nabble.com/Draw-a-table-in-Python-3.1-tp25261023p25261023.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 ggpolo at gmail.com Fri Sep 4 02:59:24 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Thu, 3 Sep 2009 21:59:24 -0300 Subject: [Tkinter-discuss] Draw a table in Python 3.1 In-Reply-To: <791153ba0909031613h3a0b06s625b1ca8b0caf4f9@mail.gmail.com> References: <25261023.post@talk.nabble.com> <791153ba0909031542r7ed06bdetb13251f6303c576f@mail.gmail.com> <791153ba0909031613h3a0b06s625b1ca8b0caf4f9@mail.gmail.com> Message-ID: 2009/9/3 Peter Milliken : > BTW, I have been looking at the Tktable from that source and it doesn't look > like a straightforward process at all! Despite the fact the author of > README.txt claims you can build it with cygwin if TEA is installed (not > really clear what TEA is although I found a web-page, but the configure > script tells me I have it installed on my system :-)), I certainly can't! > If you then try and go down the route of using Visual Studio then you run > into having to have Tcl8.4 installed - which I don't and since Tcl appears > to be up to 8.5 and 8.6 makes it even harder! > So I would suggest that you contact the folk at the sourceforge project and > ask somebody to email you a pre-built windows set of binaries (and ask them > to work a bit harder on getting their Windows/cygwin port working :-)). > Peter > I would suggest using the Tcl/Tk distribution from ActiveState, that is what I've done to (easily) use tktable on Windows before. -- -- Guilherme H. Polo Goncalves From supersimha at gmail.com Fri Sep 4 10:08:05 2009 From: supersimha at gmail.com (simha) Date: Fri, 4 Sep 2009 01:08:05 -0700 (PDT) Subject: [Tkinter-discuss] Draw a table in Python 3.1 In-Reply-To: References: <25261023.post@talk.nabble.com> <791153ba0909031542r7ed06bdetb13251f6303c576f@mail.gmail.com> <791153ba0909031613h3a0b06s625b1ca8b0caf4f9@mail.gmail.com> Message-ID: <25289513.post@talk.nabble.com> Hi Guilherme Polo, Can you please me in a little detail how to install tktable module with the python 3.1 version. I really need it badly and since you have used it, can you please read me through the steps. Also if you have a working Tktable module, can you please provide it to me. My mail id is supersimha at gmail.com Thanks in advance Guilherme Polo wrote: > > 2009/9/3 Peter Milliken : >> BTW, I have been looking at the Tktable from that source and it doesn't >> look >> like a straightforward process at all! Despite the fact the author of >> README.txt claims you can build it with cygwin if TEA is installed (not >> really clear what TEA is although I found a web-page, but the configure >> script tells me I have it installed on my system :-)), I certainly can't! >> If you then try and go down the route of using Visual Studio then you run >> into having to have Tcl8.4 installed - which I don't and since Tcl >> appears >> to be up to 8.5 and 8.6 makes it even harder! >> So I would suggest that you contact the folk at the sourceforge project >> and >> ask somebody to email you a pre-built windows set of binaries (and ask >> them >> to work a bit harder on getting their Windows/cygwin port working :-)). >> Peter >> > > I would suggest using the Tcl/Tk distribution from ActiveState, that > is what I've done to (easily) use tktable on Windows before. > > > -- > -- Guilherme H. Polo Goncalves > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > -- View this message in context: http://www.nabble.com/Draw-a-table-in-Python-3.1-tp25261023p25289513.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From harm.kirchhoff at web.de Mon Sep 7 03:28:38 2009 From: harm.kirchhoff at web.de (Harm Kirchhoff) Date: Mon, 07 Sep 2009 03:28:38 +0200 Subject: [Tkinter-discuss] Draw a table in Python 3.1 Message-ID: <1376436888@web.de> I looked into the same problem a while ago and I was not able to make the Tktable gadget work on windows. If you ever manage, it would be great if you could post a detailed step-to-step list. I found an alternative that worked even better in my case. There is a MultiListBox gadget (several versions exist) that emulates a table by putting a number of synchronized lists next to each other. It features sorting, so that the table can be resorted by any column at a mouse click and some other good features. Bigest set back is that it is not good for numerical calculations. The fields are left adjusted and summing up &c. is optically not nice to implement. HK From michael.odonnell at uam.es Mon Sep 7 10:24:13 2009 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Mon, 7 Sep 2009 10:24:13 +0200 Subject: [Tkinter-discuss] Draw a table in Python 3.1 In-Reply-To: <1376436888@web.de> References: <1376436888@web.de> Message-ID: <47e491110909070124t4bc0e73dt9a56013716d2e7ea@mail.gmail.com> I use the following all-tkinter code to make a table. If it lacks functionality, you can edit the code. from Tkinter import * from tkFont import Font from math import floor class Spreadsheet(Frame): def __init__(self, parent, font=None, **keywords): Frame.__init__(self, parent) self.columns=[] # Setup font information if font: self.txtFont=font else: self.txtFont=Font(family="Arial", size=14) self.defaultRowHeight=self.txtFont['size']+7 self.headerFont=self.txtFont.copy() self.headerFont.configure(weight='bold') self.spreadsheet=Canvas(self, bg='white', bd=0, highlightthickness=0, **keywords) self.header=Canvas(self, height=self.defaultRowHeight+2, bd=0, highlightthickness=0, bg='white') self.header.pack(side=TOP, expand=FALSE, fill=X, pady=0) self.scrollY = Scrollbar(self, orient=VERTICAL, command=self.spreadsheet.yview ) self.scrollX = Scrollbar(self, orient=HORIZONTAL, command=self.xview ) self.spreadsheet["xscrollcommand"] = self.scrollX.set self.spreadsheet["yscrollcommand"] = self.scrollY.set self.scrollY.pack(side="right", fill="y") self.scrollX.pack(side="bottom", fill="x") self.spreadsheet.pack(fill="both", expand=True, side="left") # Set up the mousewheel to scroll self.spreadsheet.focus_set() self.spreadsheet.bind("", self.mouseScroll) # Store current cursor (the one to restore to after a change) self.defaultCursor=self.cget("cursor") self.bind("", self.catchResize) def catchResize(self, event): try: self.after_cancel(self.config_id) except: pass self.config_id = self.after(500, self.optimiseColumns) def xview(self, *args): self.header.xview(*args) self.spreadsheet.xview(*args) def initialise(self): self.spreadsheet.delete(ALL) # Any window items still bound, destroy for c in self.spreadsheet.children.values(): c.destroy() self.columns=[] self.rows=[] self.startCol=0 self.startRow=0 self.totalHeight=0 def mouseScroll(self, event): if event.delta >0: self.spreadsheet.yview("scroll", "-1", "units") else: self.spreadsheet.yview("scroll", "1", "units") def setupColumns(self, columns): self.columns=[] for i in range(0, len(columns)): column=columns[i] name=column[0] width=column[1] if len(column)>2: align=column[2] else: align=CENTER self.columns.append([name,width,align]) def addColumn(self, label, width=50, align=LEFT, bg='white', fg='black'): col=dict() col['label']=label col['width']=width col['align']=align col['bg']=bg col['fg']=fg self.columns.append(col) def addRow(self, pos, row): row=Row(row) row.height=self.getRowHeight(row) row.widgets=[] col=0 for item in row: colDat=self.columns[col] if isinstance(item, Widget): row.widgets.append(item) item.internal=False else: e=Entry(self.spreadsheet, bg=colDat['bg'], fg=colDat['fg'], font=self.txtFont, justify=colDat['align']) e.internal=True e.insert(END, item) if colDat['align']==RIGHT: e.xview(END) row.widgets.append(e) col += 1 if pos==END: self.rows.append(row) else: self.rows.insert(pos, row) def getRowHeight(self, row): maxh=0 for item in row: maxh=max(maxh, self.valHeight(item)) return maxh def optimiseColumns(self, fixedWidth=True): if not self.columns: return # 1. Find the current total totWidth=0 for column in self.columns: totWidth+=column['width'] # Minimise columns which can be newWidth=0 for col in range(0, len(self.columns)): maxwidth=self.neededWidth(col) colObj=self.columns[col] if maxwidthnewWidth: # we have free space expand=[] for col in range(0, len(self.columns)): coldat=self.columns[col] reqwidth=self.neededWidth(col) if reqwidth>coldat['width']: expand.append((coldat, reqwidth-coldat['width'])) # Now, we assign each col an equal share of the free space, # up to their max requirement free=swidth-newWidth expand.sort(cmp=lambda a, b: cmp(a[1], b[1])) while expand: if free<1: break col,req=expand.pop() req=min(free, req) col['width']+=req free=free-req self.show() def neededWidth(self, col): maxwidth=self.headerFont.measure(self.columns[col]['label']) for row in self.rows: wdth=self.valWidth(row[col]) maxwidth=max(wdth, maxwidth) return maxwidth+6 def valWidth(self, val): if isinstance(val, basestring): return self.txtFont.measure(val) try: return val.winfo_reqwidth() except: pass def valHeight(self, val): if isinstance(val, basestring): return self.defaultRowHeight try: return val.winfo_reqheight() except: pass ########################################## # REDRAWING # REDRAW after change of screensize # Called after screen resize or the first time def show(self): self.spreadsheet.delete(ALL) self.redrawHeader() self.redrawSheet() def redrawHeader(self): self.header.delete(ALL) x=5 height=self.defaultRowHeight+2 self.header.create_line(x, 2, x, height) count=0 for col in self.columns: width=col['width'] self.header.create_rectangle(x+1, 3, x+width-1, height-1, fill="#c1c2ef", outline="#c1c2ef") self.header.create_line(x, 2, x+width, 2) self.header.create_line(x, height, x+width, height) self.header.create_line(x+width, 2, x+width, height, tags=('colend', str(count))) self.header.create_text(x+width/2, 1, text=col['label'], anchor=N, font=self.headerFont, tags=('title', str(count))) # for the endline use a rect of width 3, but the border same as background # Basically, this gives us a widget of 3 pix width for detecting enter/leave events self.header.create_rectangle(x+width-1, 2, x+width+1, height, fill='black', outline="#c1c2ef", tags=('colend', str(count))) x+=width count+=1 self.header["scrollregion"]=(0,0, x+self.scrollY.winfo_reqwidth(), height) # Make sure all controls are on top self.header.tag_raise('colend') self.header.tag_bind("colend", "", self.enterColEnd) self.header.tag_bind("colend", "", self.leaveColEnd) self.header.tag_bind("colend", "", self.startDrag) self.header.tag_bind("title", "", self.orderByColumn) def redrawSheet(self): if not self.rows: return # now show the data y=0 for row in self.rows: height=row.height x=5 col=-1 for value in row.widgets: col+=1 width=self.columns[col]['width'] self.drawCell(x, y, width, height, value, self.columns[col]) x+=width y+=height self.spreadsheet["scrollregion"]=(0,0, x, y) def orderByColumn(self, event): wgt=self.header.find_withtag('current') colID=int(self.header.gettags(wgt)[1]) self.sortOnColumn(colID) def enterColEnd(self, event): self.header.configure(cursor='sb_h_double_arrow') def leaveColEnd(self, event): self.header.configure(cursor=self.defaultCursor) def startDrag(self, event): self.wgt1=self.header.find_withtag('current') self.currCol=self.columns[int(self.header.gettags(self.wgt1)[1])] self.startX=self.header.bbox(self.wgt1)[0] self.header.bind('', self.moveBorder) self.header.bind('', self.stopMoveBorder) def moveBorder(self, event): self.header.tag_raise(self.wgt1) wgt_x=self.header.bbox(self.wgt1)[0] diff=event.x-wgt_x self.header.move(self.wgt1, diff, 0) def stopMoveBorder(self, event): self.header.unbind('') self.header.unbind('') self.grab_release() wgt_x=self.header.bbox(self.wgt1)[0] change=wgt_x-self.startX self.currCol['width']+=change self.show() def drawCell(self, x, y, width, height, value, col): if value.internal: self.spreadsheet.create_window(x, y, window=value, height=height, width=width, anchor=NW) else: wheight=min(height-2,value.winfo_reqheight()) self.spreadsheet.create_window(x+width/2, y+height/2, window=value, height=wheight, anchor=CENTER) def sortOnColumn(self, colID): self.rows.sort(cmp=lambda a, b, c=colID: cmp(a[c], b[c])) self.show() class Row(list): def __init__(self, vals): if isinstance(vals, tuple): vals=list(vals) list.__init__(self, vals) self.height=0 if __name__ == '__main__': tk = Tk() ssw = Spreadsheet(tk, width=900) ssw.pack(side=TOP, expand=TRUE, fill=BOTH) ssw.initialise() ssw.addColumn('', 110) ssw.addColumn('Subject', 300, bg='light blue') ssw.addColumn('Sender', 200, align=CENTER) ssw.addColumn('Date', 200, align=RIGHT) # if embedded widgets do not have ssw.spreadsheet as parent, they will overlap the border for i in range(0,20): but=Button(ssw.spreadsheet, text="View", font="Arial 8") ssw.addRow(END, (but, 'Important Message: %d' % i, 'John Doe', '10/10/%04d' % (1900-i))) ssw.optimiseColumns() ssw.show() tk.mainloop() From supersimha at gmail.com Fri Sep 11 17:05:07 2009 From: supersimha at gmail.com (simha) Date: Fri, 11 Sep 2009 08:05:07 -0700 (PDT) Subject: [Tkinter-discuss] Tktable module for python 3.1 Message-ID: <25402719.post@talk.nabble.com> Hi all, Need some help. I found out a module Tktable to draw a table, access the cell contents and retrieve data, put data etc., But I am not able to use the module. Can anyone help me with the installation. I am trying to do this on windows... The module is available at http://sourceforge.net/projects/tktable/files/ If anyone have already used it, then please help me setting up the module... My mail id is supersimha at gmail.com(supersimha(at)gmail(dot)com) The code for Tktable is as said below import tktable table = tktable.Table(parent, rows = 5, cols = 5 ) -- View this message in context: http://www.nabble.com/Tktable-module-for-python-3.1-tp25402719p25402719.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From mark_eastwood at ntlworld.com Sun Sep 13 03:34:09 2009 From: mark_eastwood at ntlworld.com (thicket) Date: Sat, 12 Sep 2009 18:34:09 -0700 (PDT) Subject: [Tkinter-discuss] Help on subclassing - Tkinter.Menu Message-ID: <25419747.post@talk.nabble.com> Hi - I'm building menus based on data from a configuration file - to date I've created standard python classes to represent the menu data then used Tkinter to retrieve the information and create the menu widgets. So I thought why not take it a step further and combine the two - sample test code below #!/usr/bin/env python from Tkinter import * class MyMenu(Menu): def __init__(self,parent): Menu.__init__(self,parent, tearoff=0) self.label1="Mylabel" self.label2="Myexit" def my_add(self): self.add_command(label=self.label1, command=root.quit) # did not expect this to work Menu.add_command(self,label=self.label2, command=root.quit) # this I thought may work root = Tk() menubar = Menu(root) menu=MyMenu(menubar) menu.my_add() menubar.add_cascade(label="Test", menu=menu) root.config(menu=menubar) mainloop() What I would like to do is not hardcode the 'tearoff=0' in the parent class constructor i.e. instantiate MyMenu by menu=MyMenu(menubar, tearoff=0) Also not 100% sure why both add_command() statements in my_add() work? Thanks -- View this message in context: http://www.nabble.com/Help-on-subclassing---Tkinter.Menu-tp25419747p25419747.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From klappnase at web.de Sun Sep 13 11:56:20 2009 From: klappnase at web.de (Michael Lange) Date: Sun, 13 Sep 2009 11:56:20 +0200 Subject: [Tkinter-discuss] Help on subclassing - Tkinter.Menu In-Reply-To: <25419747.post@talk.nabble.com> References: <25419747.post@talk.nabble.com> Message-ID: <20090913115620.c973039d.klappnase@web.de> Hi, On Sat, 12 Sep 2009 18:34:09 -0700 (PDT) thicket wrote: (...) > > #!/usr/bin/env python > from Tkinter import * > > class MyMenu(Menu): > def __init__(self,parent): > Menu.__init__(self,parent, tearoff=0) > self.label1="Mylabel" > self.label2="Myexit" > > def my_add(self): > self.add_command(label=self.label1, > command=root.quit) > # did not expect this to work > Menu.add_command(self,label=self.label2, > command=root.quit) > # this I thought may work > > root = Tk() > menubar = Menu(root) > menu=MyMenu(menubar) > menu.my_add() > menubar.add_cascade(label="Test", menu=menu) > > root.config(menu=menubar) > mainloop() > > What I would like to do is not hardcode the 'tearoff=0' in the parent > class constructor i.e. instantiate MyMenu by > menu=MyMenu(menubar, tearoff=0) You can achieve this by changing the MyMenu constructor so it will accept keyword arguments and pass them to the Menu class. class MyMenu(Menu): def __init__(self,parent, **kw): Menu.__init__(self,parent, **kw) > > Also not 100% sure why both add_command() statements in my_add() work? In your example "root" is defined globally. It would not work if you put root = Tk() and the following lines inside a function definition and then the script calls this function. If you want it to be more obvious you can keep a reference to the parent inside the MyMenu class, so the constrctor may look like: class MyMenu(Menu): def __init__(self,parent, **kw): Menu.__init__(self,parent, **kw) self.parent = parent However, as long as you need only the quit() method from "root", you can use self.quit() as well, because any Tkinter widget has a quit() method. HTH Michael From mark_eastwood at ntlworld.com Sun Sep 13 14:27:24 2009 From: mark_eastwood at ntlworld.com (thicket) Date: Sun, 13 Sep 2009 05:27:24 -0700 (PDT) Subject: [Tkinter-discuss] Help on subclassing - Tkinter.Menu In-Reply-To: <20090913115620.c973039d.klappnase@web.de> References: <25419747.post@talk.nabble.com> <20090913115620.c973039d.klappnase@web.de> Message-ID: <25422810.post@talk.nabble.com> Michael it does (help) - thank you cheers Michael Lange wrote: > > Hi, > > On Sat, 12 Sep 2009 18:34:09 -0700 (PDT) > thicket wrote: > > (...) >> >> #!/usr/bin/env python >> from Tkinter import * >> >> class MyMenu(Menu): >> def __init__(self,parent): >> Menu.__init__(self,parent, tearoff=0) >> self.label1="Mylabel" >> self.label2="Myexit" >> >> def my_add(self): >> self.add_command(label=self.label1, >> command=root.quit) >> # did not expect this to work >> Menu.add_command(self,label=self.label2, >> command=root.quit) >> # this I thought may work >> >> root = Tk() >> menubar = Menu(root) >> menu=MyMenu(menubar) >> menu.my_add() >> menubar.add_cascade(label="Test", menu=menu) >> >> root.config(menu=menubar) >> mainloop() >> >> What I would like to do is not hardcode the 'tearoff=0' in the parent >> class constructor i.e. instantiate MyMenu by >> menu=MyMenu(menubar, tearoff=0) > > You can achieve this by changing the MyMenu constructor so it will > accept keyword arguments and pass them to the Menu class. > > class MyMenu(Menu): > def __init__(self,parent, **kw): > Menu.__init__(self,parent, **kw) > >> >> Also not 100% sure why both add_command() statements in my_add() work? > > In your example "root" is defined globally. It would not work if you > put root = Tk() and the following lines inside a function definition > and then the script calls this function. > If you want it to be more obvious you can keep a reference to the > parent inside the MyMenu class, so the constrctor may look like: > > class MyMenu(Menu): > def __init__(self,parent, **kw): > Menu.__init__(self,parent, **kw) > self.parent = parent > > However, as long as you need only the quit() method from "root", you > can use self.quit() as well, because any Tkinter widget has a quit() > method. > > HTH > > Michael > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > -- View this message in context: http://www.nabble.com/Help-on-subclassing---Tkinter.Menu-tp25419747p25422810.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From bradley.h at aggiemail.usu.edu Tue Sep 15 19:48:50 2009 From: bradley.h at aggiemail.usu.edu (Bradley Hintze) Date: Tue, 15 Sep 2009 13:48:50 -0400 Subject: [Tkinter-discuss] Horizontal scroll canvas Message-ID: <3933e78c0909151048td49dde3jdbc313900c04184b@mail.gmail.com> I am trying to make a scrollable canvas in the horizontal direction but I am having a difficult time. I get the whole scroll bar and can scroll using the arrows on the ends of the scroll bar but the actual bar (the slider bar) takes up the whole scrollbar area as if there is nothing to scroll. Thus, the slider bar cannot be used to scroll. (It may be easier to understand if you just run the snipit of code) I am wondering how I can fix this. Here is my code: from Tkinter import * from tkFileDialog import * import os class analyze_notes: def __init__(self): string='' for i in range(0,100):string=string+' '+str(i) self.comp_1=Tk() self.comp_1.title('Try') l1=Label(self.comp_1, text='Try canvas').grid() c1_xscroll=Scrollbar(self.comp_1, orient=HORIZONTAL) c1_xscroll.grid(row=2, sticky=E+W+N) c1=Canvas(self.comp_1, height=150, width=400, relief=SUNKEN, xscrollcommand=c1_xscroll.set) c1.grid(row=1) c1_xscroll.config(command=c1.xview) self.topic_label = Label(c1, text=string, font=('courier',10), bg='white') c1.create_window(0, 50, window=self.topic_label, anchor=NW) self.comp_1.mainloop() r=analyze_notes() Thanks in advance, -- Bradley J. Hintze Graduate Student Duke University School of Medicine 801-712-8799 From klappnase at web.de Tue Sep 15 20:13:30 2009 From: klappnase at web.de (Michael Lange) Date: Tue, 15 Sep 2009 20:13:30 +0200 Subject: [Tkinter-discuss] Horizontal scroll canvas In-Reply-To: <3933e78c0909151048td49dde3jdbc313900c04184b@mail.gmail.com> References: <3933e78c0909151048td49dde3jdbc313900c04184b@mail.gmail.com> Message-ID: <20090915201330.9a8976c5.klappnase@web.de> Hi, On Tue, 15 Sep 2009 13:48:50 -0400 Bradley Hintze wrote: > I am trying to make a scrollable canvas in the horizontal direction > but I am having a difficult time. I get the whole scroll bar and can > scroll using the arrows on the ends of the scroll bar but the actual > bar (the slider bar) takes up the whole scrollbar area as if there is > nothing to scroll. Thus, the slider bar cannot be used to scroll. (It > may be easier to understand if you just run the snipit of code) I am > wondering how I can fix this. > Here is my code: > > from Tkinter import * > from tkFileDialog import * > import os > class analyze_notes: > > def __init__(self): > string='' > for i in range(0,100):string=string+' '+str(i) > self.comp_1=Tk() > self.comp_1.title('Try') > l1=Label(self.comp_1, text='Try canvas').grid() > c1_xscroll=Scrollbar(self.comp_1, orient=HORIZONTAL) > c1_xscroll.grid(row=2, sticky=E+W+N) > c1=Canvas(self.comp_1, height=150, width=400, relief=SUNKEN, > xscrollcommand=c1_xscroll.set) > c1.grid(row=1) > c1_xscroll.config(command=c1.xview) > self.topic_label = Label(c1, text=string, font=('courier',10), > bg='white') > c1.create_window(0, 50, window=self.topic_label, anchor=NW) > self.comp_1.mainloop() > > r=analyze_notes() > You did not define the Canvases scrollregion; this must be a 4-tuple (x0, y0, x1, y1) defining the part of the canvas that should be accessible through the scrollbars. In your case it should be fine to add a line c1.configure(scrollregion=c1.bbox('all')) to your code right before the call to mainloop() . Please note that you might have to update the widget's scrollregion each time the canvases contents are changed. HTH Michael From halbert at halwitz.org Thu Sep 17 18:31:12 2009 From: halbert at halwitz.org (Dan Halbert) Date: Thu, 17 Sep 2009 12:31:12 -0400 (EDT) Subject: [Tkinter-discuss] ImageTk.PhotoImage: empty image not holding its size Message-ID: <1253205072.029319442@192.168.1.70> Hi, I have a picky question about using an empty ImageTk.PhotoImage. I am trying to create a placeholder space for an image that will be supplied later - something like this: root = Tk() pimage = ImageTk.PhotoImage('RGB', (300,300)) image_holder = Label(root, image=pimage) image_holder.grid() However, the result is a a tiny window, not one with a 300x300 empty space. If I do pimage.paste(...) later with a real image, it grows as expected to fit the image. I could set the width and height of the Label to 300x300 when I create it, but shouldn't the empty PhotoImage act like a 300x300 image? Thanks, Dan From mbg at progress.com Fri Sep 18 12:00:16 2009 From: mbg at progress.com (Moray Grieve) Date: Fri, 18 Sep 2009 06:00:16 -0400 Subject: [Tkinter-discuss] Threading issue with Tkinter Frame.insert Message-ID: <2EBB4E57935D4948AEA54C8C74DA66FC04327265@MAIL02.bedford.progress.com> The code fragment below has an example where a Tk GUI is launched as a separate thread - this all works fine in Python 2.5, but in Python 2.6 the thread hangs. The issue seems to be in the line; self.messageBoxDetails.insert(INSERT, "Hello world") Comment this line out, or use an empty string rather than "Hello World", and the example works in both Python 2.5 and Python 2.6. I have not been able to see any related issues to this and wonder if this is a bug in the 2.6 Tkinter module? Thanks for any assistance. -Moray --------------------- import time, thread from Tkinter import * class ExampleError: def __init__(self): self.parentContainer = Tk() self.parentContainer.protocol('WM_DELETE_WINDOW', self.quitPressed) self.parentContainer.wm_geometry("500x400") self.parentContainer.title("Parent Container Title") self.container = Frame(self.parentContainer) self.messageBoxDetails = Text(self.container, wrap=WORD, width=1, height=1, padx=10, pady=10) # in python 2.6, this next statement hangs when running as a thread - note that # inserting an empty string works though self.messageBoxDetails.insert(INSERT, "d") self.messageBoxDetails.pack(fill=BOTH, expand=YES, side=LEFT) self.container.pack(fill=BOTH, expand=YES, padx=5, pady=5) def quitPressed(self): self.stop() def start(self): self.parentContainer.mainloop() def stop(self): self.parentContainer.quit() self.parentContainer.destroy() if __name__ =="__main__": example = ExampleError() time.sleep(1) thread.start_new_thread(example.start, ()) time.sleep(5) -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/png Size: 174 bytes Desc: image002.png URL: From klappnase at web.de Fri Sep 18 20:59:11 2009 From: klappnase at web.de (Michael Lange) Date: Fri, 18 Sep 2009 20:59:11 +0200 Subject: [Tkinter-discuss] Threading issue with Tkinter Frame.insert In-Reply-To: <2EBB4E57935D4948AEA54C8C74DA66FC04327265@MAIL02.bedford.progress.com> References: <2EBB4E57935D4948AEA54C8C74DA66FC04327265@MAIL02.bedford.progress.com> Message-ID: <20090918205911.7b2df443.klappnase@web.de> Hi Moray, On Fri, 18 Sep 2009 06:00:16 -0400 "Moray Grieve" wrote: > The code fragment below has an example where a Tk GUI is launched as a > separate thread - this all works fine in Python 2.5, but in Python 2.6 > the thread hangs. The issue seems to be in the line; > > > > self.messageBoxDetails.insert(INSERT, "Hello world") > > > > Comment this line out, or use an empty string rather than "Hello > World", and the example works in both Python 2.5 and Python 2.6. I > have not been able to see any related issues to this and wonder if > this is a bug in the 2.6 Tkinter module? > > Here (python-2.5.2 on debian linux) I get the following error message: Unhandled exception in thread started by Traceback (most recent call last): File "test.py", line 49, in start self.parentContainer.mainloop() File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1026, in mainloop self.tk.mainloop(n) RuntimeError: Calling Tcl from different appartment I never saw this before, but it seems to nicely point on to what is wrong with your code. You are trying to communicate with Tk from two different threads which is generally a bad idea. Sometimes this may be a source of confusion because the same code seems to work on one system an crashes on another, the problem is that you never seem to know in advance. The canonical way of using threads with Tkinter is to make sure that all calls to the Tk interpreter are done from the main program thread; if you need communication between a child thread and Tk, it should be done for example by changing some variable's value from within the child thread and periodically polling these variable's value from the Tk thread. I hope this helps Michael > > Thanks for any assistance. > > > > -Moray > > > > > > --------------------- > > import time, thread > > from Tkinter import * > > > > class ExampleError: > > def __init__(self): > > self.parentContainer = Tk() > > self.parentContainer.protocol('WM_DELETE_WINDOW', > self.quitPressed) > > self.parentContainer.wm_geometry("500x400") > > self.parentContainer.title("Parent Container Title") > > > > self.container = Frame(self.parentContainer) > > self.messageBoxDetails = Text(self.container, wrap=WORD, > width=1, height=1, padx=10, pady=10) > > > > # in python 2.6, this next statement hangs when running as > # a > thread - note that > > # inserting an empty string works though > > self.messageBoxDetails.insert(INSERT, "d") > > self.messageBoxDetails.pack(fill=BOTH, expand=YES, > side=LEFT) > > > > self.container.pack(fill=BOTH, expand=YES, padx=5, pady=5) > > > > def quitPressed(self): > > self.stop() > > > > def start(self): > > self.parentContainer.mainloop() > > > > def stop(self): > > self.parentContainer.quit() > > self.parentContainer.destroy() > > > > > > > > if __name__ =="__main__": > > example = ExampleError() > > time.sleep(1) > > thread.start_new_thread(example.start, ()) > > time.sleep(5) > > > > From lionkimbro at gmail.com Mon Sep 28 00:38:18 2009 From: lionkimbro at gmail.com (Lion Kimbro) Date: Sun, 27 Sep 2009 15:38:18 -0700 Subject: [Tkinter-discuss] Python 3.1; canvas rectangle dash & dashoffset Message-ID: <497072fd0909271538o13720085u7cbdfecf05e4f93e@mail.gmail.com> Dear tkinter peoples, I'm having difficulties with dash, and dashoffset; Can anyone identify what I'm doing wrong? - Code: ---------------------------------------------------- import tkinter def move_dashes(canvas, rect, offset): print("move_dashes(%s, %s, %s)" % (canvas, rect, offset)) canvas.itemconfigure(rect, dashoffset=offset) canvas.after(1000, move_dashes, canvas, rect, offset+1) def dashoffset_test(): # Create a canvas canvas = tkinter.Canvas() canvas.pack() # Put a comparison rectangle on the canvas. canvas.create_rectangle(7, 2, 27,28, outline="blue", dash=(5,1)) # Put a rectangle on the canvas with a moving dash pattern. rect = canvas.create_rectangle(10,5, 30,30, dash=(4,1)) canvas.after(1000, move_dashes, canvas, rect, 1) canvas.mainloop() dashoffset_test() ============================================================ Two questions: 1. Why are the dash patterns so wildly different? canvas.create_rectangle(7, 2, 27,28, outline="blue", dash=(5,1)) canvas.create_rectangle(10,5, 30,30, dash=(4,1)) The first looks like: xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx The second looks like: xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx ...and yet, it's just (5,1) vs. (4,1) This is not what I expect from: http://infohost.nmt.edu/tcc/help/pubs/tkinter/dash-patterns.html 2. Why doesn't the dash pattern move? The call to canvas.itemconfigure(rect, dashoffset=offset) looks correct; Am I doing it wrong? I am using Python 3.1 Thank you, Lion Kimbro -------------- next part -------------- An HTML attachment was scrubbed... URL: