I have a button that when pressed is supposed to keep printing a certain phrase. However I have an if statement that's supposed to break out of the while loop if it reads that the button is released. Essentially, I'm trying to create a gui that, when a specific button is pressed it continues to act out a function until that button is released in tkinter. I believe that there should be a statement which reads the state of the button and knows when the button is released, but I don't know what it is.
self.button.pack(side="top")
self.vsb.pack(side="right", fill="y")
self.text.pack(side="bottom", fill="x")
self.button.bind("<ButtonPress>", self.on_press)
self.button.bind("<ButtonRelease>", self.on_release)
def on_press(self, event):
while True:
time.sleep(1)
self.log("button was pressed")
if (what do I put here):
break