Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: rantingrickjohnson@gmail.com Newsgroups: comp.lang.python Subject: Re: Tkinter.event.widget: handler gets name instead of widget. Date: Sat, 14 Jul 2012 20:10:27 -0700 (PDT) Organization: http://groups.google.com Lines: 83 Message-ID: References: <1341782353.2041.136.camel@hatchbox-one> <89816e26-fc20-4cdc-ba6c-f252231d43ba@f16g2000yqg.googlegroups.com> NNTP-Posting-Host: 166.249.194.253 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1342321828 8162 127.0.0.1 (15 Jul 2012 03:10:28 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 15 Jul 2012 03:10:28 +0000 (UTC) Cc: python-list@python.org In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=166.249.194.253; posting-account=h3aEwQoAAACiuqX-oR3gvCVFm8lLHoWj User-Agent: G2/1.0 X-Received-Bytes: 5169 Xref: csiph.com comp.lang.python:25330 On Thursday, July 12, 2012 1:53:54 PM UTC-5, Frederic Rentsch wrote: > The "hit list" is a table of investment titles (stock, funds, bonds) > that displays upon entry of a search pattern into a respective template. > The table displays the matching records: name, symbol, ISIN, CUSIP, Sec. > Any line can be click-selected. So they are to look like buttons. Hmm. If they "appear" like a button widget anyway, then why not just use a = button widget? > Representing the mentioned names and id codes in Label widgets was the > simplest way I could come up with to align them in columns, admittedly > without the benefit of much experience. But it does look good. the > layout is fine. But is it really the "simplest"? :) ## START CODE ## import Tkinter as tk from Tkconstants import * colWidths =3D (5,10,30,5) N_COLS =3D len(colWidths) N_ROWS =3D 6 root =3D tk.Tk() for r in range(N_ROWS): # Create some imaginary text to display in each column. # Also try using string methods "center" and "rjust" to # see alternative justification of text. lst =3D [str(r).ljust(colWidths[r]) for r in range(N_COLS)] b=3Dtk.Button(root, text=3D''.join(lst)) b.pack(padx=3D5, pady=3D5) root.mainloop() ## END CODE ## You could easily expand that into something reusable. Now. If you need to place fancy borders around the texts, or use multiple f= onts, or use images, or blah blah blah... then you may want to use the "can= vas items" provided by the Tkinter.Canvas widget INSTEAD of buttons.=20 With the canvas, you can create a simple rectangle (canvas.create_rectangle= ) that represents a button's outside dimension and give it a "button styled= " border. Then you can bind click events to mimic the button press action. = Then you can place canvas_text items on top of that fake button and configu= re them to be invisible to click events. These text items will not interfer= like the Tkinter.Label widgets are currently doing.=20 However, i would suggest the Tkinter.Button solution is the easiest by far. > I find the Tkinter system quite challenging. Doing a layout isn't so > much a matter of dimensioning and placing things as a struggle to trick > a number of automatic dimensioning and placing mechanisms into > obliging--mechanisms that are rather numerous and hard to remember. I don't think i agree with that assessment.=20 ## START TANGENTIAL MEANDERINGS ## I find the geometry management of Tkinter to be quite powerful whilst being= simultaneously simplistic. You only have three main types of management: "= Grid", "Place", and "Pack". Each of which has a very specific usage. One ca= veat to know is that you can NEVER mix "Grid" and "Pack" in the same contai= ner widget! I find myself using grid and pack the most, with grid being at = the top of the list. Now, i will agree that grid can be confusing at first until you understand = how to "rowconfigure" and "columnconfigue" the containing widget (be it a f= rame or a toplevel). There is also the "sticky" attribute to consider.=20 ## END TANGENTIAL MEANDERINGS ## But all in all, i would say the most difficult part of the Tkinter geometry= management API is coming to grips as to which of the three geometry manage= rs is the best choice for the particular problem at hand -- and you will fi= nd yourself using more than one manager in a single GUI app! But i don't see you solving this problem by stacking one widget on another.= I believe it's time to seek out a new solution. EASY: Using rows of Tkinter.Button coupled with a per-formatted text string= . ADVANCED: Creating "pseudo buttons" on a canvas and stacking text objects (= or whatever you like) on them.