Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining Tkinter and win32ui makes Python crash on exit

While building a basic app using the winapi with Python 2.7 (I'm on Windows 8.1), I tried to add a small Tkinter gui to the program. The problem is, whenever I close the app window, Python crashes completely (getting crash messages basically).

I have found reports of this issue in several places, but couldn't find a fix or solution. Here are some sources:

http://sourceforge.net/p/pywin32/bugs/443/#8bde

http://www.gossamer-threads.com/lists/python/python/134956 (this one is from 2002!)

It can be reproduced with as much as these 4 lines:

from Tkinter import Tk
import win32ui

root = Tk()
root.mainloop()

And closing the window after running it. Does anyone know of a solution for this? Any recommendations for a workaround maybe?

like image 383
eyalzek Avatar asked Feb 25 '15 15:02

eyalzek


People also ask

How to exit a program in Python Tkinter?

Python Tkinter Exit Program. To quit a program we need to destroy the window. There is a built-in method destroy() to close the window in Python Tkinter. Syntax: Here ws is the main window & is the variable for Tk() class method. ws.destroy() Here is the the small demonstration of Python Tkinter Exit Program. Code:

What is Tkinter in Python?

I’ve been working on a minor python project recently, and went back to my old friend TkInter. TkInter is the standard GUI library for Python. I had used it previously in another small project, so when I wanted to quickly get a GUI going for a project, it made sense to use TkInter.

Is it possible to quit a Tkinter app from idle?

This is in most cases what you want, because your Tkinter-app will also stop. It can be a problem, if you e.g. call your app from idle. idle is itself a Tkinker-app, so if you call quit () in your app and the TCL interpreter gets terminated, idle will also terminate (or get confused ;)).

How do I Close a Tkinter window?

Import the tkinter library and create an instance of tkinter frame. Set the size of the frame using geometry method. Define a function close () to close the window. Call the method win.destroy () inside close ().


1 Answers

A workaround is to invoke the Tkinter-win32UI app with pythonw. Python doesn't crash.

Tested with Python 3.6.3 on Win 10.

like image 191
Tarqez Avatar answered Sep 17 '22 11:09

Tarqez