tkinter socket client ?

Russell E. Owen rowen at cesmail.net
Tue Jan 25 13:29:16 EST 2005


In article <1106659122.977876.234250 at z14g2000cwz.googlegroups.com>,
 "Tonino" <tonino.greco at gmail.com> wrote:

>thanks for this info - I had to abandon the createfilehandler() method
>as it is not supported in windows and the GUI "might" be used there at
>some time ...
>
>So - I went the threading route - works well - for now - so I will
>stick to it ...
>
>BUT - the next question:
>In the Text() widget - why - when the text scrolls off the screen -
>does the window not follow it ?
>
>I have added a scrollbar to it :
>
>self.center_frame = Frame(self.top_frame, background="tan",
>relief=RIDGE)
>
>self.text=Text(self.center_frame,background='white')
>scroll=Scrollbar(self.center_frame)
>self.text.configure(yscrollcommand=scroll.set)
>
>self.text.pack(side=LEFT, fill=BOTH, expand=YES)
>scroll.pack(side=RIGHT,fill=Y)
>self.center_frame.pack(side=RIGHT, expand=YES, fill=BOTH)
>
>
>but the window does not scroll to follow the text ?
>Any ideas ?

That's just how it works. But when you append text you can easily tell 
the text widget to display it, e.g. using "see". Here is the code I use 
(from RO.Wdg.LogWdg.py), which has these useful features:
- auto-scrolls only if the user is already scrolled to the of text (so 
if a user is staring at some older data, it won't be jerked out from 
under them)
- deletes excess text.

def addOutput(self, astr, category=None):
    """Add a line of data to the log.
    
    Inputs:
    - astr: the string to append. If you want a newline, specify the \n 
yourself.
    - category: name of category or None if no category
    """
    # set auto-scroll flag true if scrollbar is at end
    # there are two cases that indicate auto-scrolling is wanted:
    # scrollPos[1] = 1.0: scrolled to end
    # scrollPos[1] = scrollPos[0]: window has not yet been painted
    scrollPos = self.yscroll.get()
    doAutoScroll = scrollPos[1] == 1.0 or scrollPos[0] == scrollPos[1]
    if category:
        self.text.insert("end", astr, (category,))
    else:
        self.text.insert("end", astr)
    extraLines = int(float(self.text.index("end")) - self.maxLineIndex)
    if extraLines > 0:
        self.text.delete("1.0", str(extraLines) + ".0")
    if doAutoScroll:
        self.text.see("end")

-- Russell



More information about the Python-list mailing list