Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12861

Re: Tkinter label height to fit content

From Bart Kastermans <bkasterm@gmail.com>
Newsgroups comp.lang.python
Subject Re: Tkinter label height to fit content
Date 2011-09-06 18:33 -0600
Organization MB-NET.NET for Open-News-Network e.V.
Message-ID <8762l5jin7.fsf@gmail.com> (permalink)
References (3 earlier) <8d7cf6e4-5794-4f57-88ae-b0d0dcfd68a6@d25g2000yqh.googlegroups.com> <87obyx4ed4.fsf@gmail.com> <8777abed-e2b1-469e-96e5-662c535220be@y21g2000yqy.googlegroups.com> <87k49l49gs.fsf@gmail.com> <af467c29-d1c5-4a42-b1ec-91e0afba6819@d25g2000yqh.googlegroups.com>

Show all headers | View raw


rantingrick <rantingrick@gmail.com> writes:

> On Sep 6, 5:00 pm, Bart Kastermans <bkast...@gmail.com> wrote:
>> rantingrick <rantingr...@gmail.com> 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 </sarcasm> :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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Tkinter label height to fit content Bart Kastermans <bkasterm@gmail.com> - 2011-09-03 16:15 -0600
  Re: Tkinter label height to fit content rantingrick <rantingrick@gmail.com> - 2011-09-03 18:15 -0700
    Re: Tkinter label height to fit content Bart Kastermans <bkasterm@gmail.com> - 2011-09-04 13:39 -0600
      Re: Tkinter label height to fit content rantingrick <rantingrick@gmail.com> - 2011-09-04 14:10 -0700
        Re: Tkinter label height to fit content Bart Kastermans <bkasterm@gmail.com> - 2011-09-06 14:15 -0600
          Re: Tkinter label height to fit content rantingrick <rantingrick@gmail.com> - 2011-09-06 14:23 -0700
            Re: Tkinter label height to fit content rantingrick <rantingrick@gmail.com> - 2011-09-06 14:37 -0700
            Re: Tkinter label height to fit content Bart Kastermans <bkasterm@gmail.com> - 2011-09-06 16:00 -0600
              Re: Tkinter label height to fit content rantingrick <rantingrick@gmail.com> - 2011-09-06 15:40 -0700
                Re: Tkinter label height to fit content rantingrick <rantingrick@gmail.com> - 2011-09-06 15:43 -0700
                Re: Tkinter label height to fit content Bart Kastermans <bkasterm@gmail.com> - 2011-09-06 18:33 -0600
      Re: Tkinter label height to fit content rantingrick <rantingrick@gmail.com> - 2011-09-04 14:15 -0700

csiph-web