Feb-09-2022, 04:58 PM
My program renders a score. The render() function is a big heavy function. Inside a thread I run a while loop that checks if a connected midi controller sends a note on message and if so it writes that note to the file and runs the heavy render() function inside the thread. The problem is that this works way slower resulting in a short blink on the screen every time you insert a note using the midi controller which is anoying.
The goal is to call the render function from the mainloop so it runs the heavy function in the main program / not inside a thread. Is this possible in a way?
I made a small tkinter example where we have a thread while loop. How can i call the render function inside the while loop in a way that it uses the tkinter mainloop()?
When I use root.bind() the function gets called in the mainloop()
I hope there is a simple answer :)
The goal is to call the render function from the mainloop so it runs the heavy function in the main program / not inside a thread. Is this possible in a way?
I made a small tkinter example where we have a thread while loop. How can i call the render function inside the while loop in a way that it uses the tkinter mainloop()?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
from tkinter import Tk from time import sleep from threading import Thread root = Tk() def render(): print ( 'render the score!' ) def whileloopthread(): while True : sleep( 1 ) render() # how to call this function from the mainloop? Thread(target = whileloopthread).start() root.mainloop() |
I hope there is a simple answer :)