# 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 "qt_tk_demo.py", line 50 in # # This crash happens in _tkinter.c in PythonCmd inside the ENTER_PYTHON macro. import sys # Hello-World with PyQt from PyQt5 import QtWidgets, QtCore qtapp = QtWidgets.QApplication(sys.argv) qtwindow = QtWidgets.QWidget() qtbutton = QtWidgets.QPushButton("Hello Qt", qtwindow) qtbutton.pressed.connect(lambda: QtWidgets.QMessageBox.information(qtwindow, "Test Qt", "Qt Button was pressed")) qtwindow.show() # Hello-World with Tkinter import tkinter from tkinter import messagebox tkroot = tkinter.Tk() tkroot.withdraw() tkwindow = tkinter.Toplevel(tkroot) tkinter.Button(tkwindow, text="Hello Tk", command=lambda: messagebox.showinfo("Test Tk", "Tk Button was pressed")).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) # Feed Tkinter event loop from Qt timer = QtCore.QTimer() def update_tk(): tkroot.update() timer.start() timer.timeout.connect(update_tk) timer.setSingleShot(True) timer.start(50) # Run Qt application sys.exit(qtapp.exec_())