Push to Make (Single Pole) Button running a loop

J

Jon Todd

Happy holidays all!

I'm developing an application and, as a relative newbie to Python, have come
across a stumbling block with Tkinter.

I'd like to have a button that when pressed executes a loop (this could be a
thread) and then stops execution when it's released (Push to Make - Single
Pole in electronics terms).

I've tried the regular way of associating the procedure with a callback and
tried using <Button-1> and <ButtonRelease-1> bindings but am getting nowhere
fast (in the latter case the button release event seems to occur anyhows).

So my question is: Is there a neat way of doing this? And would it
necessarily involve creating a custom widget?

....

Also, while I'm here, what's the state of play regarding non-ASCII in
Tkinter widgets. I've been trying to get our currency symbol, £, to display
but didn't have much luck even playing with the coding: settings.

TIA

jon
 
D

Dennis Lee Bieber

I'd like to have a button that when pressed executes a loop (this could be a
thread) and then stops execution when it's released (Push to Make - Single
Pole in electronics terms).
We must have separate backgrounds -- that would be a "momentary
contact, normally open" switch to me...
I've tried the regular way of associating the procedure with a callback and
tried using <Button-1> and <ButtonRelease-1> bindings but am getting nowhere
fast (in the latter case the button release event seems to occur anyhows).
Minimum runnable sample code would be appreciated...

I suspect your "loop" /will/ need to be a separate thread, which
tests a variable each time through to see if it can continue -- or,
maybe better since you don't want it busy waiting when it is "not
running", use an Event or Condition object. The button callbacks would
set/clear the E/C object, and the loop would block on the object if it
is one of the two states.

If you are trying to work the loop inside the button-down callback,
then the loop is going to block the rest of the GUI from processing
events.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
H

Hendrik van Rooyen

Jon Todd said:
I'd like to have a button that when pressed executes a loop (this could be a
thread) and then stops execution when it's released (Push to Make - Single
Pole in electronics terms).

I've tried the regular way of associating the procedure with a callback and
tried using <Button-1> and <ButtonRelease-1> bindings but am getting nowhere
fast (in the latter case the button release event seems to occur anyhows).

You are a bit stymied :

Afaik, Button needs the click on the button, leaving it depressed,
while ButtonRelease needs a click on the button, and the release can be anywhere
for drag and drop implementation. So it is possible to call two routines with
one
click and release.

But there is another hassle - you would have to code the loop as a separate
thread,
started by the first, while the second routine sets some variable that is
checked by
the loop to kill itself, as the GUI will not be responsive until the first
command
returns, because the command "captures" the main loop...

HTH - Hendrik
 
S

Sambo

Hendrik said:
You are a bit stymied :

Afaik, Button needs the click on the button, leaving it depressed,
while ButtonRelease needs a click on the button, and the release can be anywhere
for drag and drop implementation. So it is possible to call two routines with
one
click and release.

But there is another hassle - you would have to code the loop as a separate
thread,
started by the first, while the second routine sets some variable that is
checked by
the loop to kill itself, as the GUI will not be responsive until the first
command
returns, because the command "captures" the main loop...

HTH - Hendrik
Perhaps besides all the multithreading issues you should be looking at different kind
of control/button ei. checkbox or radio button (windows terminology)?

My first experience at GUI with Tk/TCL?? was not a good one due to both
lack of docs and fear it wouldn't work on both LUNUX and vindows.

Wish there was a simple library with basic primitives like create_windows resize,
get_client_area and of course some functions to hand of control to the system.
At least for me, that way I could get much further much faster than trying to
find the learn the behavior of all the currently available controls.
Another point I came across recently is that there is no information on proper
cleanup after TCL, don't remember exactly why it was a problem it is after all OOP sy.
So, you may have to read the sourcecode for everything you are using and it ain't easy,

Good Luck.

Cheers.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top