[Tutor] Disable output buffer with some tkinter thrown in.
intatia at paradise.net.nz
Thu Nov 27 06:36:51 EST 2003
I am doing a little python scripting for kmuddy, a mud client, this involves
receiving, having a look at, and occasionaly sending stuff back.
What is sent/received is always plain text through stdin and stdout.
Firstly when I first started off I came across a problem where everything I sent
back (via a print statement) came up only after the script had finished, a quick
post on the kmuddy led me to using sys.stdout.flush() after each print
statement, but it was also mentioned that in other languages it's possible to
disable the output buffer entirely.
Mentioned in perl: ,$|=1;
and in C/C++ as: setvbuf (stdout, 0, _IONBF, 0);
How do I do this in python?
Secondly I am running into a similar problem when using Tkinter, createing a
root window and inserting labels. It creates the Tkinter window but then it just
sits there without the labels being added in, closing the tkinter window
produces the following traceback :
Traceback (most recent call last):
Script info has finished with return code 1. <<<--This line is from kmuddy
File "/home/intatia/script/infomation.py", line 7, in ?
Label(root, tex="Hello").grid(row=0, column=0)
File "/usr/local/lib/python2.3/lib-tk/Tkinter.py", line 2370, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "/usr/local/lib/python2.3/lib-tk/Tkinter.py", line 1835, in __init__
_tkinter.TclError: can't invoke "label" command: application has been destroyed
This script works perfectly and as expected when run by itself from the command
line. I can only assume it is running into the same problem as the print
statements were, some sort of output buffer?
Any ideas? Thoughts? Musings? Random gueses?:)
Python 2.3 on Mandrake9.1
As an explanation on what I'm doing as a whole, I'm aiming at creating a script
that intercepts says/goss/clantell/tell (Communication from other players) into
window for easier (and slower) reading. And perhaps eventually putting in the
capacity to reply on the appropriate channel.
More information about the Tutor