tkinter test field, scrolling, threads

Discussion in 'Python' started by Bob Greschke, Feb 27, 2004.

  1. Bob Greschke

    Bob Greschke Guest

    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_tasks() 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! =-----
     
    Bob Greschke, Feb 27, 2004
    #1
    1. Advertisements

  2. Bob Greschke

    Eric Brunel Guest

    Bob Greschke wrote:
    > 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_tasks() 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?


    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=LEFT, fill=BOTH)
    vs = Scrollbar(root, orient=VERTICAL, command=t.yview)
    vs.pack(side=RIGHT, fill=Y)
    t.configure(yscrollcommand=vs.set)
    root.update()

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

    th = threading.Thread(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
     
    Eric Brunel, Mar 1, 2004
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    578
    Eugene Druker
    Jun 14, 2005
  2. D

    Tkinter Scrolling

    D, Feb 1, 2007, in forum: Python
    Replies:
    4
    Views:
    406
  3. Skybuck Flying

    Call oddities: &Test() vs &Test vs Test

    Skybuck Flying, Oct 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    995
    Skybuck Flying
    Oct 4, 2009
  4. Felipe Ochoa

    Tkinter scrolling

    Felipe Ochoa, Oct 27, 2009, in forum: Python
    Replies:
    0
    Views:
    924
    Felipe Ochoa
    Oct 27, 2009
  5. Ren Wenshan
    Replies:
    2
    Views:
    1,392
    Ren Wenshan
    Dec 29, 2009
  6. Sebastian Lisken

    scrolling, or rather shifting, text field contents

    Sebastian Lisken, May 5, 2006, in forum: Javascript
    Replies:
    0
    Views:
    116
    Sebastian Lisken
    May 5, 2006
  7. Sound
    Replies:
    2
    Views:
    719
    Randy Webb
    Sep 28, 2006
  8. jr
    Replies:
    3
    Views:
    666
Loading...