Path: csiph.com!usenet.pasdenom.info!news.albasani.net!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.nosignal.org!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'skip:[ 20': 0.03; 'configure': 0.04; 'root': 0.04; 'attribute': 0.05; 'canvas': 0.07; 'tkinter': 0.07; 'api': 0.09; 'events.': 0.09; 'grid': 0.09; 'lst': 0.09; 'rows': 0.09; 'template.': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'gui': 0.11; 'suggest': 0.11; 'represents': 0.15; 'bind': 0.16; 'canvas,': 0.16; 'caveat': 0.16; 'dimension': 0.16; 'fancy': 0.16; 'fine.': 0.16; 'hmm.': 0.16; 'invisible': 0.16; 'simplest': 0.16; 'symbol,': 0.16; 'string': 0.17; 'wrote:': 0.17; 'widget': 0.17; 'solution.': 0.18; '(or': 0.18; 'respective': 0.20; 'all,': 0.21; 'import': 0.21; 'cc:2**0': 0.23; 'matching': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'creating': 0.26; 'expand': 0.26; 'displays': 0.27; 'easiest': 0.27; 'label': 0.27; 'mix': 0.27; 'skip:( 20': 0.28; 'container': 0.29; 'far.': 0.29; 'items"': 0.29; 'objects': 0.29; 'thursday,': 0.30; 'button': 0.30; 'code': 0.31; 'good.': 0.32; 'could': 0.32; 'align': 0.33; 'problem': 0.33; 'entry': 0.33; 'agree': 0.34; 'received:google.com': 0.34; 'text': 0.34; 'whatever': 0.35; 'solving': 0.35; 'text.': 0.35; 'doing': 0.35; 'table': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'list.': 0.35; 'really': 0.36; 'but': 0.36; '12,': 0.36; 'display': 0.36; 'does': 0.37; 'being': 0.37; 'why': 0.37; 'quite': 0.37; 'rather': 0.37; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'some': 0.38; 'things': 0.38; 'instead': 0.39; 'easily': 0.39; 'skip:" 10': 0.40; 'end': 0.40; 'think': 0.40; 'july': 0.60; 'managers': 0.60; 'from:no real name:2**0': 0.60; 'most': 0.61; 'matter': 0.61; 'containing': 0.61; 'first': 0.61; 'mentioned': 0.63; 'more': 0.63; 'management': 0.65; 'experience.': 0.65; 'investment': 0.67; 'believe': 0.69; 'benefit': 0.70; 'press': 0.71; 'click': 0.76; 'yourself': 0.77; 'hand': 0.82; 'action.': 0.84; 'column.': 0.84; 'confusing': 0.84; 'coupled': 0.84; 'management:': 0.84; 'sec.': 0.84; 'subject:gets': 0.84; 'texts,': 0.84; 'numerous': 0.91; 'funds,': 0.93 Newsgroups: comp.lang.python Date: Sat, 14 Jul 2012 20:10:27 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=166.249.194.253; posting-account=h3aEwQoAAACiuqX-oR3gvCVFm8lLHoWj References: <1341782353.2041.136.camel@hatchbox-one> <89816e26-fc20-4cdc-ba6c-f252231d43ba@f16g2000yqg.googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 166.249.194.253 MIME-Version: 1.0 Subject: Re: Tkinter.event.widget: handler gets name instead of widget. From: rantingrickjohnson@gmail.com To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 83 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342321830 news.xs4all.nl 6887 [2001:888:2000:d::a6]:47071 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25331 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.