I have written a little Script that listens to MIDI events (sent by a DJ Mixer via usb) and sends UDP Packets to an IP adress (to switch Camera Angle). This works well, and i wanted to use it as a Standalone App in OSX. Since py2app does not show a console output, i tried to use a GUI instead. So i found an example of how to make a Tkinter GUI that outputs the Console text.
Both Programms work on their own, but when i try to do it all in one .py script, Python Crashes (with the OSX send report thing coming up).
Even when i run the scripts in Spyder, one after the other, it gives me random errors, and the Console needs to be restarted.
How can this be? i don't even have an error displayed...
import sys
from tkinter import Tk, Button, Frame
from tkinter.scrolledtext import ScrolledText
import os
import socket
import pygame as pg
import pygame.midi
class PrintLogger(object): # create file like object
def __init__(self, textbox): # pass reference to text widget
self.textbox = textbox # keep ref
def write(self, text):
self.textbox.configure(state="normal") # make field editable
self.textbox.insert("end", text) # write text to textbox
self.textbox.see("end") # scroll to end
self.textbox.configure(state="disabled") # make field readonly
def flush(self): # needed for file like object
pass
class MainGUI(Tk):
def __init__(self):
Tk.__init__(self)
self.title = "Camera Switcher"
self.root = Frame(self)
self.root.pack()
# self.redirect_button = Button(self.root, text="Redirect console to widget", command=self.redirect_logging)
# self.redirect_button.pack()
# self.redirect_button = Button(self.root, text="Redirect console reset", command=self.reset_logging)
# self.redirect_button.pack()
self.test_button = Button(self.root, text="Test Print", command=self.test_print)
self.test_button.pack()
self.log_widget = ScrolledText(self.root, height=40, width=90, font=("consolas", "8", "normal"))
self.log_widget.pack()
logger = PrintLogger(self.log_widget)
sys.stdout = logger
sys.stderr = logger
lastFaderUpCount = 0
# input_main(0)
def test_print(self):
print("Am i working?")
def main():
lastFaderUpCount = 0
input_main(0)
def input_main(device_id=None):
global app
pg.init()
pg.fastevent.init()
event_get = pg.fastevent.get
event_post = pg.fastevent.post
pygame.midi.init()
if __name__ == "__main__":
app = MainGUI()
app.title = "Camera Switcher"
input_main(0)
Sorry for the messy code... its copied together from many different sources...
Updated with a shorter version, the GUI stuff was all copied from here: How can I displaymy console output in TKinter?
The console output is:
runfile('/Users/mathiasgmunder/Library/CloudStorage/OneDrive-Personal/03_DJ/07_Tools/Camera Automation OSX/Camera_Switcher_mini.py', wdir='/Users/mathiasgmunder/Library/CloudStorage/OneDrive-Personal/03_DJ/07_Tools/Camera Automation OSX')
pygame 2.1.2 (SDL 2.0.18, Python 3.9.12)
Hello from the pygame community. https://www.pygame.org/contribute.html
/Applications/Spyder.app/Contents/Resources/lib/python3.9/spyder/plugins/ipythonconsole/scripts/conda-activate.sh: line 18: 19366 Abort trap: 6 $CONDA_ENV_PYTHON -m spyder_kernels.console -f $SPYDER_KERNEL_SPEC
Restarting kernel...