# This is a minimal example to demonstrate a crash on resizing a Tkinter # window on Windows, if Tkinter doesn't own the main loop. # # Fatal Python error: PyEval_RestoreThread: NULL tstate # # Current thread 0x00001140 (most recent call first): # File "simple_tk_demo.py", line 33 in # # This crash happens in _tkinter.c in PythonCmd inside the ENTER_PYTHON macro. # Hello-World with Tkinter import tkinter from tkinter import messagebox tkroot = tkinter.Tk() tkroot.withdraw() tkwindow = tkinter.Toplevel(tkroot) tkinter.Label(tkwindow, text="Hello Tk").pack() # Bind the tkwindow event def on_tk_configure(event): print(event) color = '#{:02x}{:02x}{:02x}'.format(event.width % 0xFF, event.height % 0xFF, event.x % 0xFF) tkwindow.config(bg=color) tkwindow.bind("", on_tk_configure) # Update once so that the dialog is shown tkroot.update() # Show a native Windows dialog import ctypes MessageBox = ctypes.windll.user32.MessageBoxW MessageBox(None, 'Hello', 'Window title', 0)