tkinter test field, scrolling, threads

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Greschke

    tkinter test field, scrolling, threads

    I have a program where the user pushes a button, a "starting" message is
    ..inserted to a text field with an associated scroll bar, a thread is started
    that inserts a "working... " message on to the end of the text field until
    stopped, or until the loop finishes. The loop sleeps for about 3 seconds
    every time through (I'm just prototyping at this point). The mainloop just
    waits for the user to hit the same button again which will set a flag and
    cause the thread to terminate early, otherwise it doesn't have anything to
    do. update()'s and update_idle_tas ks() get called anytime anything is
    written to the text field. Everything works fine until the text field fills
    up then the program just freezes with no errors on the console window. If I
    change the starting of a thread to a regular function call then everything
    works fine.

    What is going wrong?

    Bob




    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
  • Eric Brunel

    #2
    Re: tkinter test field, scrolling, threads

    Bob Greschke wrote:[color=blue]
    > I have a program where the user pushes a button, a "starting" message is
    > .inserted to a text field with an associated scroll bar, a thread is started
    > that inserts a "working... " message on to the end of the text field until
    > stopped, or until the loop finishes. The loop sleeps for about 3 seconds
    > every time through (I'm just prototyping at this point). The mainloop just
    > waits for the user to hit the same button again which will set a flag and
    > cause the thread to terminate early, otherwise it doesn't have anything to
    > do. update()'s and update_idle_tas ks() get called anytime anything is
    > written to the text field. Everything works fine until the text field fills
    > up then the program just freezes with no errors on the console window. If I
    > change the starting of a thread to a regular function call then everything
    > works fine.
    >
    > What is going wrong?[/color]

    If you do not post any code, it will be difficult for anyone to help you.
    Knowing your Python and tcl/tk versions and your platform will help too.

    I know that there are some issues regarding Tkinter and threads, but the
    following code works:

    --text+threads.py------------------
    from Tkinter import *
    import time, threading

    root = Tk()
    t = Text(root, width=8, height=4)
    t.pack(side=LEF T, fill=BOTH)
    vs = Scrollbar(root, orient=VERTICAL , command=t.yview )
    vs.pack(side=RI GHT, fill=Y)
    t.configure(ysc rollcommand=vs. set)
    root.update()

    def thLoop():
    i = 0
    while 1:
    t.insert(END, 'spam %s\n' % i)
    i += 1
    time.sleep(1)

    th = threading.Threa d(target=thLoop )
    th.setDaemon(1)
    th.start()

    root.mainloop()
    -----------------------------------

    Tested with Python 2.1.1, tcl/tk 8.3.2 on Linux Mandrake 8.0
    --
    - Eric Brunel <eric dot brunel at pragmadev dot com> -
    PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

    Comment

    • Bob Greschke

      #3
      Re: tkinter test field, scrolling, threads

      Eric Brunel <eric.brunel@N0 SP4M.com> wrote in message news:<c1uubt$vl h$1@news-reader2.wanadoo .fr>...[color=blue]
      > Bob Greschke wrote:[color=green]
      > > I have a program where the user pushes a button, a "starting" message is
      > > .inserted to a text field with an associated scroll bar, a thread is started
      > > that inserts a "working... " message on to the end of the text field until
      > > stopped, or until the loop finishes. The loop sleeps for about 3 seconds
      > > every time through (I'm just prototyping at this point). The mainloop just
      > > waits for the user to hit the same button again which will set a flag and
      > > cause the thread to terminate early, otherwise it doesn't have anything to
      > > do. update()'s and update_idle_tas ks() get called anytime anything is
      > > written to the text field. Everything works fine until the text field fills
      > > up then the program just freezes with no errors on the console window. If I
      > > change the starting of a thread to a regular function call then everything
      > > works fine.
      > >
      > > What is going wrong?[/color]
      >
      > If you do not post any code, it will be difficult for anyone to help you.
      > Knowing your Python and tcl/tk versions and your platform will help too.
      >
      > I know that there are some issues regarding Tkinter and threads, but the
      > following code works:
      >
      > --text+threads.py------------------
      > from Tkinter import *
      > import time, threading
      >
      > root = Tk()
      > t = Text(root, width=8, height=4)
      > t.pack(side=LEF T, fill=BOTH)
      > vs = Scrollbar(root, orient=VERTICAL , command=t.yview )
      > vs.pack(side=RI GHT, fill=Y)
      > t.configure(ysc rollcommand=vs. set)
      > root.update()
      >
      > def thLoop():
      > i = 0
      > while 1:
      > t.insert(END, 'spam %s\n' % i)
      > i += 1
      > time.sleep(1)
      >
      > th = threading.Threa d(target=thLoop )
      > th.setDaemon(1)
      > th.start()
      >
      > root.mainloop()
      > -----------------------------------
      >
      > Tested with Python 2.1.1, tcl/tk 8.3.2 on Linux Mandrake 8.0[/color]

      Sorry...this is WinXP, Python 2.3.3

      I'm still messing with this. Your program seems to work fine. No
      matter how I mess with it I can't get it to fail, but even if I strip
      a lot out of mine it keeps behaving badly. But it is even wierder.
      If I "print" any ol' thing to the IDLE console window from a thread,
      and keep doing it until the console window fills up to the point where
      it should start to scroll, everything IDLE crashes and freezes. The
      exact same code works fine on RH9 Python 2.2.2, and Solaris 8 Python
      2.1.1. For now I've just turned off the scroll bars when in Windows.
      I'd post code, but the program is now pretty big and I'm not sure what
      to keep or throw out.

      Thanks!

      Comment

      • Eric Brunel

        #4
        Re: tkinter test field, scrolling, threads

        Bob Greschke wrote:
        [snip][color=blue]
        > I'm still messing with this. Your program seems to work fine. No
        > matter how I mess with it I can't get it to fail, but even if I strip
        > a lot out of mine it keeps behaving badly. But it is even wierder.
        > If I "print" any ol' thing to the IDLE console window from a thread,
        > and keep doing it until the console window fills up to the point where
        > it should start to scroll, everything IDLE crashes and freezes. The
        > exact same code works fine on RH9 Python 2.2.2, and Solaris 8 Python
        > 2.1.1.[/color]

        Did you try to run your script outside of IDLE, i.e. just by opening a DOS
        console and type "python myScript.py"? Since IDLE is itself written with
        Tkinter, there may a few problems between your script and IDLE itself.

        HTH
        --
        - Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
        PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

        Comment

        Working...