473,770 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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! =-----
Jul 18 '05 #1
3 2333
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_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?


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

Jul 18 '05 #2
Eric Brunel <er*********@N0 SP4M.com> wrote in message news:<c1******* ***@news-reader2.wanadoo .fr>...
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_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?


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


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!
Jul 18 '05 #3
Bob Greschke wrote:
[snip]
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.


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

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1570
by: Charles Starrett | last post by:
I am a just a dabbler in programming, but I'd like to make some simple cross-platform tools for generating webpages, as well as for text munging. One thing I need is a Mac OS 9/Windows GUI solution. I thought that Tkinter could provide this, but I'm having trouble getting the simple test script from Learning Python p.22 to work under Mac OS 9 (9.2.2, on a 400 MHz PowerBook firewire/2000, 192 MB ram). Starting with a clean install of...
7
10706
by: Jane Austine | last post by:
As you add more items, say text lines, in Text widget, it gets too slow and almost impractical to use on. Take idle for example. If the text gets bigger(e.g. print urllib.urlopen('http://www.amazon.com').read() ), it becomes too sluggish to use as an "interactive" shell. I have tried wxPython and it seems to have the same problem (from my experience using PyCrust). Is there any way to speed up Text widget, or should I look for another
2
6697
by: klappnase | last post by:
Hello everyone, I have seen several threads here on this problem, but still cannot figure out the solution. I want to create a window icon for a Tkinter application and tried several things that are supposed to work. Here is a little demo of what I tried: #################################from Tkinter import * icon1 = ('''#define im_width 26 #define im_height 25
1
3859
by: corrado | last post by:
Hello I have an application running several thread to display some financial data; basically I have a thread displaying HTML tables by means of Tkhtml, another implementing a scrolling ticker based on a Text widget with embedded windows and a thread running the Tkinter mainloop plus several other thread dealing with the scheduling of the contents and the acquisition of data but not using graphic widgets. I run the same code on Linux...
1
2976
by: syed_saqib_ali | last post by:
Please take a look at and run the code snippet shown below. It creates a canvas with vertical & Horizontal scroll-bars. If you shrink the window to smaller than the area of the canvas, the scroll-bars work as advertised. That's great. However, if you click the Left Mouse button, it calls code which expands the width of the canvas by 100 pixels. The area being viewed expands correspondingly..... BUT I DON'T WANT IT TO!!
14
2695
by: Hendrik van Rooyen | last post by:
Hi, I get the following: hvr@LINUXBOXMicrocorp:~/Controller/libpython display.py UpdateStringProc should not be invoked for type font Aborted and I am back at the bash prompt - this is most frustrating, as there is no friendly traceback to help me guess where its coming from.
2
9578
by: Kevin Walzer | last post by:
I'm trying to decide whether I need threads in my Tkinter application or not. My app is a front end to a command-line tool; it feeds commands to the command-line program, then reads its output and displays it in a Tkinter text widget. Some of the commands are long-running and/or return thousands of lines of output. I initially thought I needed to use threading, because the GUI would block when reading the output, even when I configured...
2
3960
by: Kevin Walzer | last post by:
I'm porting a Tkinter application to wxPython and had a question about wxPython's event loop. The Tkinter app provides a GUI to a command-line tool. It gathers user input, and opens an asynchronous pipe to the external tool via os.popen(). Then, it dumps the output from the external process into a text display. Although threads are often recommended for use with GUI apps, I am able to keep the GUI responsive with Tkinter's event loop,...
0
916
by: Steve Holden | last post by:
Allen Taylor wrote: You can publish it in the Python package index - see http://pypi.python.org/pypi/ If you want to have it considered for inclusion into future versions of Python then you should post a bug to bugs.python.org wiht your patch as an attachment and the test of the above mail as a rationale for the change. Thanks for going to these lengths to contribute!
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10037
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8931
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.