how do i use "tkinter.createfilehandler" with a regular c program?
Jo Schambach
jschamba at physics.utexas.edu
Mon Nov 14 16:14:37 EST 2005
Thanks, that seems to work.
maybe one more question on this subject:
how can i use the callback function to the "createfilehandler" call from
within a class?
in other words, what would be the signature of the callback function, if
I made it a member of a class?
The documentation says that the callback is called with the arguments:
callback(filehandle, stateMask)
but a class member function always has the "self" argument as is first
argument. So would the syntax be:
class GUI:
def __init__:
.....
def filehandlerCallback(self, filehandle, stateMask):
....
Jo
jepler at unpythonic.net wrote:
> Compared to your program, I
> * Made sure that the slave program actually flushed its stdout buffers
> * didn't call read(), which will by default continue reading until
> it reaches EOF, not merely read the available data
>
> #!/usr/bin/env python
> import sys, time, Tkinter, itertools, _tkinter, os
>
> if '-slave' in sys.argv:
> for i in itertools.count():
> time.sleep(1)
> print "This is a line of output:", i
> sys.stdout.flush()
> raise SystemExit
>
> root = Tkinter.Tk()
> root.wm_withdraw()
>
> fh = os.popen('%s -slave' % sys.argv[0])
>
> def reader(*args):
> line = fh.readline()
> if not line:
> print "EOF from slave"
> raise SystemExit
> print "from slave: %r" % line
>
> _tkinter.createfilehandler(fh, Tkinter.READABLE, reader)
> root.mainloop()
--
Dr Joachim Schambach
The University of Texas at Austin
Department of Physics
1 University Station C1600
Austin, Texas 78712-0264, USA
Phone: (512) 471-1303; FAX: (814) 295-5111
e-mail: jschamba at physics.utexas.edu
More information about the Python-list
mailing list