Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change a variable inside of a function

Status
Not open for further replies.

josiah7

Programmer
Nov 13, 2002
4
US


Still new at Python and TK, Can someone please help me on this?
I have a button widget that calls a function. The function runs once when the button is depressed. I want the function to loop as long as the button is held down. But I need some kind of event handler for "mouse-1" to tell me if the mouse is still depressed over the button.

How can I write a function that will continue to loop as long as the button widget is pressed?

Thanks!
josiah
 
As I said, I am just starting so I need some help, please!

To expand on my problem a little for clarity, I need a event handler that detects if the mouse button is still pressed, or one that detects a <ButtonRelease> event. A way to check the STATE of the mouse event and use it to control the &quot;while loop&quot; of a function.

Heres what I had in mind;

########################################
self.mybutton = Button(frame, command=self.myfunc)
self.mybutton.pack()

def myfunc(self)
While a = 1:
# do something
Try:
if self.mybutton.<button-1> # check state of mouse-1
a=1
except:
a=0
#########################################

How can I break the loop on <ButtonRelease>, or continue to loop as long as the <MousePressed> is sending events to the widget?
Thanks for any help!
josiah
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top