Mailing List Archive

tkinter and signals
Hi everyone.
Im quite new to tkinter. I try to make a program using tkinter, that
is able to listen to some signals: read a pipe, perform periodic
actions. I first tried with SIGALRM, with a widget changing fg color
every second. I dont wait() for SIGALRM, just return in mainloop().
the behavior I get is: I need the mouse to hover on the app, to get
the SIGALRM signal. My diagnostic, right or wrong is: in the mainloop,
the idle state is a wait() for a signal (dunno which) related to an X
event. In this state, an unwaited signal just wont wake up the
process.
It just occurs to me threads might be the solution: for every possible
signal source, spawn a thread that will explicitly wait for this
signal? Im not familiar with thread either, so I better wait for a
confirmation from someone who knows....
Oh, btw, Im using Solaris 2.5.1 on X86 (its an Unix V.4)
Thanks for answering!

--
Pierre Imbaud <pierre@saiph.com>
12 Rue des Bosquets 91480 Quincy Sous Sénart France
Tel: 01 69 00 94 57 Fax 79 65
tkinter and signals [ In reply to ]
Pierre Imbaud <pierre@saiph.com> wrote:
: Hi everyone.
: Im quite new to tkinter. I try to make a program using tkinter, that
: is able to listen to some signals: read a pipe, perform periodic
: actions. I first tried with SIGALRM, with a widget changing fg color
: every second. I dont wait() for SIGALRM, just return in mainloop().
: the behavior I get is: I need the mouse to hover on the app, to get
: the SIGALRM signal. My diagnostic, right or wrong is: in the mainloop,
: the idle state is a wait() for a signal (dunno which) related to an X
: event. In this state, an unwaited signal just wont wake up the
: process.
: It just occurs to me threads might be the solution: for every possible
: signal source, spawn a thread that will explicitly wait for this
: signal? Im not familiar with thread either, so I better wait for a
: confirmation from someone who knows....
: Oh, btw, Im using Solaris 2.5.1 on X86 (its an Unix V.4)
: Thanks for answering!

I would suggest first looking into the after() and after_idle() methods.
They are designed for this type of operation.

There is also a lower-level interface, the _tkinter.createtimerhandler
function.

The after() and _tkinter.createtimerhandler() functions both take
a number of milliseconds and a function.

f = Frame(None)
oneminute = 60000
def change_red(f=f):
f.config(fd="red")
f.after(oneminute, change_green)
def change_green(f=f):
f.config(fg="green")
f.after(oneminute, change_red)
f.after(oneminute, change_red)

-Arcege