Oct-04-2022, 03:59 PM
from tkinter import * # root root = Tk() root.title('SeqTank') scrwidth = root.winfo_screenwidth() scrheight = root.winfo_screenheight() root.geometry("%sx%s+%s+%s" % (int(scrwidth / 1.5), int(scrheight / 1.25), int(scrwidth / 6), int(scrheight / 12))) root.update() # paned master with two panels panedmaster = PanedWindow(root, orient='v', sashwidth=1, relief='flat', sashcursor='arrow', bg='#666666') panedmaster.place(relwidth=1, relheight=1) uppanel = PanedWindow(panedmaster, height=35, relief='flat') panedmaster.add(uppanel) downpanel = PanedWindow(panedmaster, relief='flat') panedmaster.add(downpanel) text_editor = Text(downpanel, bg='black', fg='#32a852', insertbackground='white', font=('Courier', 24)) text_editor.place(relwidth=1, relheight=1) text_editor.focus_set() generate_button = Button(uppanel, text='Play!') generate_button.place(relwidth=1) def process(): for i in range(100): ... # playing a midi-file here generate_button.configure(command=process) root.mainloop()This is my simple tkinter interface. I created a little tool that generates a midi-file based on the text input(it uses a special lilypond-like syntax) and plays the midi file using mido in a for loop. My question is how can I break the for loop if I press the play button again before it finished the for loop? I hope someone can tell me in (regarding the above example) how I should write it different...