title: Python crash when using Tkinter and Pygame in one Script
body: <p>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.</p>
  <p>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).</p>
  <p>Even when i run the scripts in Spyder, one after the other, it gives me random errors, and the Console needs to be restarted.</p>
  <p>How can this be? i don't even have an error displayed...</p>
  <pre><code>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=&quot;normal&quot;)  # make field editable
          self.textbox.insert(&quot;end&quot;, text)  # write text to textbox
          self.textbox.see(&quot;end&quot;)  # scroll to end
          self.textbox.configure(state=&quot;disabled&quot;)  # make field readonly
  
      def flush(self):  # needed for file like object
          pass
  
  
  class MainGUI(Tk):
  
      def __init__(self):
          Tk.__init__(self)
          self.title = &quot;Camera Switcher&quot;
          self.root = Frame(self)
          self.root.pack()
          # self.redirect_button = Button(self.root, text=&quot;Redirect console to widget&quot;, command=self.redirect_logging)
          # self.redirect_button.pack()
          # self.redirect_button = Button(self.root, text=&quot;Redirect console reset&quot;, command=self.reset_logging)
          # self.redirect_button.pack()
          self.test_button = Button(self.root, text=&quot;Test Print&quot;, command=self.test_print)
          self.test_button.pack()
          self.log_widget = ScrolledText(self.root, height=40, width=90, font=(&quot;consolas&quot;, &quot;8&quot;, &quot;normal&quot;))
          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(&quot;Am i working?&quot;)
  
  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__ == &quot;__main__&quot;:
      app = MainGUI()
      app.title = &quot;Camera Switcher&quot;
      input_main(0)        
  </code></pre>
  <p>Sorry for the messy code... its copied together from many different sources...</p>
  <p>Updated with a shorter version, the GUI stuff was all copied from here:
  <a href="https://stackoverflow.com/questions/68198575/how-can-i-displaymy-console-output-in-tkinter">How can I displaymy console output in TKinter?</a></p>
  <p>The console output is:</p>
  <pre><code>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...
  </code></pre>