Apr-26-2022, 08:13 PM
(This post was last modified: Apr-26-2022, 08:13 PM by philipbergwerf.)
I have written a program that writes a music score based on a text file with a certain syntax. I use tkinter as gui and draw engine to draw the score and be able to export the score to pdf. It was much work making all this so I don't want to rewrite everything in a different way to solve the following problem:
The program does this cycle; everytime you release a key in the tkinter text widget it runs the render() function and the score gets updated. When having a few notes in the score this works really quick but when it has to render more than 400 notes every render starts to delay the text input. So only when I am quickly typing in a big score, the text widget waits for the render() function to complete before updating it's contents.
I made a little example:
The program does this cycle; everytime you release a key in the tkinter text widget it runs the render() function and the score gets updated. When having a few notes in the score this works really quick but when it has to render more than 400 notes every render starts to delay the text input. So only when I am quickly typing in a big score, the text widget waits for the render() function to complete before updating it's contents.
I made a little example:
from tkinter import * root = Tk() canvas = Canvas(root) canvas.pack() text = Text(root) text.pack() def render(event=None): ''' This functions represents a really heavy render function that can render a lot of pages and turn into the problem that the function slows down the user experience. ''' canvas.create_line(10,10,100,100) ''' we bind the KeyRelease. When we enter quickly multiple characters to the text box and the render() function has to render 10 pages of music, the text widget is going to wait for the render function to complete before updating the text widget which is anoying for the user. ''' root.bind('<KeyRelease>', render) root.mainloop()How can we program the above example in such a way that the text widget is never waiting for the render function to complete before updating itself? Typing in the text widget should always be a fluent experience. It doesn't matter if the render function takes time to complete but it shouldn't slow down the text widget.