Python Forum
How to bind a midi signal to tkinter?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to bind a midi signal to tkinter?
#1
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()?
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()
When I use root.bind() the function gets called in the mainloop()

I hope there is a simple answer :)
Reply


Messages In This Thread
How to bind a midi signal to tkinter? - by philipbergwerf - Feb-09-2022, 04:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding MIDI Channels to each Input zach1234 6 1,338 Apr-20-2023, 11:51 AM
Last Post: jefsummers
  mido MIDI-file; how to distinguis tracks? philipbergwerf 2 2,373 Dec-10-2021, 05:06 PM
Last Post: philipbergwerf
  How to open MIDI-file and get events in a list? philipbergwerf 7 5,182 May-29-2021, 08:24 AM
Last Post: j.crater
  Mido and virtual midi ports dore_m 2 4,736 Dec-27-2020, 06:02 AM
Last Post: dore_m
  MIDI FILES TEMPO - MIDO Tetsuo30 9 5,195 Sep-06-2020, 08:17 PM
Last Post: jefsummers
  Real time MIDI with python eythoralex 1 3,554 May-19-2020, 07:17 PM
Last Post: Larz60+
  Please help! Akai APC20 midi controller script versusliveact 0 2,192 Feb-14-2020, 05:37 AM
Last Post: versusliveact
  Parameters for function in bind() kom2 1 2,343 Apr-18-2019, 03:59 PM
Last Post: woooee
  Using MIDI from Python on Windows 7 PythonAndMIDIUser 3 3,530 Jun-16-2018, 06:20 AM
Last Post: buran
  MIDI Inputs NightPython42 3 58,187 Aug-10-2017, 02:37 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

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