Python Forum
How to break out of a for loop on button press?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to break out of a for loop on button press?
#2
According to your application you are not pressing a button.

In tkinter, mainloop() is the function that sees that you pressed a button and calls your function. Your process() function contains a loop that prevents mainloop() from running. According to your program you are not pressing a button because mainloop() does not get a chance check if you pressed a button. After pressing the play button your application is frozen.

The first thing you need to do is find a way to play the midi file without blocking mainloop(). You should post more information about what is involved in playing the file. Is there a way to start the playback and return immediately, or do you have to wait for completion of the file? If you can start playout and return immediately, is there a continuous play option? If no to all of those, you might need to create a separate thread for playing the midi file.
Reply


Messages In This Thread
RE: How to break out of a for loop on button press? - by deanhystad - Oct-04-2022, 07:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Button to stop while loop from another script Absolutewind 5 1,007 Sep-25-2023, 11:20 PM
Last Post: deanhystad
  Code won't break While loop or go back to the input? MrKnd94 2 1,035 Oct-26-2022, 10:10 AM
Last Post: Larz60+
  break out of for loop? User3000 3 1,510 May-17-2022, 10:18 AM
Last Post: User3000
  Asyncio: Queue consumer gets out of while loop without break. Where exactly and how? saavedra29 2 2,748 Feb-07-2022, 07:24 PM
Last Post: saavedra29
  tkinter auto press button kucingkembar 2 3,279 Dec-24-2021, 01:23 PM
Last Post: kucingkembar
  tkinter control break a while loop samtal 0 2,431 Apr-29-2021, 08:26 AM
Last Post: samtal
  Cannot 'break' from a "for" loop in a right place tester_V 9 4,066 Feb-17-2021, 01:03 AM
Last Post: tester_V
  How to break a loop in this case? Blainexi 10 7,389 Sep-24-2020, 04:06 PM
Last Post: Blainexi
  how to break the loop? bntayfur 8 3,129 Jun-07-2020, 11:07 PM
Last Post: bntayfur
  break for loop Agusben 1 1,966 Apr-01-2020, 05:07 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020