Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!newsfeed.straub-nv.de!news.mb-net.net!open-news-network.org!.POSTED!not-for-mail From: Bart Kastermans Newsgroups: comp.lang.python Subject: Re: Tkinter label height to fit content Date: Tue, 06 Sep 2011 18:33:32 -0600 Organization: MB-NET.NET for Open-News-Network e.V. Lines: 82 Message-ID: <8762l5jin7.fsf@gmail.com> References: <87mxelgtmx.fsf@gmail.com> <69ce4e11-5ef4-4b81-b66b-87d1017b1ec3@s7g2000yqk.googlegroups.com> <87obz0w0ze.fsf@gmail.com> <8d7cf6e4-5794-4f57-88ae-b0d0dcfd68a6@d25g2000yqh.googlegroups.com> <87obyx4ed4.fsf@gmail.com> <8777abed-e2b1-469e-96e5-662c535220be@y21g2000yqy.googlegroups.com> <87k49l49gs.fsf@gmail.com> NNTP-Posting-Host: kasterma.colorado.edu Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: gwaiyur.mb-net.net 1315355614 21984 128.138.150.65 (7 Sep 2011 00:33:34 GMT) X-Complaints-To: abuse@open-news-network.org NNTP-Posting-Date: Wed, 7 Sep 2011 00:33:34 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-User-ID: U2FsdGVkX1/p8NO6w+HdSGJ3S1GqOIzsw+1eu/DHHqP5s45CHMhJxvOqQGMPntPP Cancel-Lock: sha1:dbABzNvW5mn5sju6lVMaPZ2sUzs= sha1:5llIG7HEYTcemrhA0+Ut/BggFrU= Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12861 rantingrick writes: > On Sep 6, 5:00 pm, Bart Kastermans wrote: >> rantingrick writes: >> > Hmm, i can replace all that code with this... >> >> Because I stupidly forgot to repeat the original problem I had, and my >> code doesn't show it (and doesn't show the correct use of the function I >> wrote). > > Oh NOW i see! This new code you posted is like night and day compared > to the original :o) Quite, I should know better (I deal with students thinking what is in their mind should be clear to me all the time): ############################################## # run through all the data we have, compute the maximum height max_ht = 0 for i in range(0,len(data)): # lin.count is the line counting function ct = lin.count(data[i], 450) if ct > max_ht: max_ht = ct for i in range(0,min(len(data),5)): # l is the Tkinter.Label with all formatting applied and data[i] # set for text l['height'] = max_ht # use this maximum height for all Labels. ############################################### Thinking on this some more, the first computation should surely be max_ht = max (map (lambda x: lin.count(x, 450), data)) The second one could then be labels = map (label_prepare_pack, data[:5]) where label_prepare_pack prepares (sets all attributes and data), packs, and returns the new label. The first (for max_ht) is a clear improvement to me, the second (for labels) uses too many side-effects to be very appealing to me. > Anyway, i did not read the code to find the difference because i want > to know why you insist on using multiple labels for this when a > scrolled text will suffice. Are you trying to create some sort of > textual "animation frames" that you can flip through on demand? I don't follow precisely, but I am indeed looking to flip through all of data while showing only 5 or 10 at a time. The problem I wanted to solve was that my window kept changing size while doing this. > If not > i would use the scrolled text (and even the scrolled text can "feel" > like animation frames whist scrolling). > > Take your input data and replace ALL single newlines with null strings > (thereby preserving paragraphs) and let the textbox control the line > wrapping. The benefits are enormous using my way; your way is limited > and requires re-inventing the wheel. Tell me WHY the textbox approach > is not a viable solution and THEN i'll listen to you. The reason I thought this, was that I didn't realize I could bind actions to tags (to get different actions for different bits of text). Now that I do know this I could use code like my lin.count to get the maximum height still (to get a constant location for the i-th item as the items are changed; more importantly to get a constant height for the whole list of items), and then use tags to bind the corresponding actions. > Until then; you can lead a horse to water... I certainly appreciate your trying. I might not see the fresh stream yet, but I do see liquid (possibly a shallow muddy pool, but big progress from the dry sandy dunes before). I will keep both approaches in mind as I further develop. Again, thanks for the help, greatly appreciated.