<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Microsoft Theme 2.00" content="axis 010">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Verdana",sans-serif;
        color:black;}
h1
        {mso-style-priority:9;
        mso-style-link:"Heading 1 Char";
        margin-top:12.0pt;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:0in;
        margin-bottom:.0001pt;
        page-break-after:avoid;
        font-size:16.0pt;
        font-family:"Verdana",sans-serif;
        color:black;}
h2
        {mso-style-priority:9;
        mso-style-link:"Heading 2 Char";
        margin-top:2.0pt;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:0in;
        margin-bottom:.0001pt;
        page-break-after:avoid;
        font-size:14.0pt;
        font-family:"Verdana",sans-serif;
        color:black;
        font-weight:normal;}
h3
        {mso-style-priority:9;
        mso-style-link:"Heading 3 Char";
        margin-top:2.0pt;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:0in;
        margin-bottom:.0001pt;
        page-break-after:avoid;
        font-size:13.0pt;
        font-family:"Verdana",sans-serif;
        color:black;
        font-weight:normal;}
h4
        {mso-style-priority:9;
        mso-style-link:"Heading 4 Char";
        margin-top:2.0pt;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:0in;
        margin-bottom:.0001pt;
        page-break-after:avoid;
        font-size:14.0pt;
        font-family:"Verdana",sans-serif;
        color:black;
        font-weight:normal;}
h5
        {mso-style-priority:9;
        mso-style-link:"Heading 5 Char";
        margin-top:2.0pt;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:0in;
        margin-bottom:.0001pt;
        page-break-after:avoid;
        font-size:13.0pt;
        font-family:"Verdana",sans-serif;
        color:black;
        font-weight:normal;}
h6
        {mso-style-priority:9;
        mso-style-link:"Heading 6 Char";
        margin-top:2.0pt;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:0in;
        margin-bottom:.0001pt;
        page-break-after:avoid;
        font-size:11.0pt;
        font-family:"Verdana",sans-serif;
        color:black;
        font-weight:normal;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#339933;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#996600;
        text-decoration:underline;}
span.Heading1Char
        {mso-style-name:"Heading 1 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 1";
        font-family:"Verdana",sans-serif;
        color:black;
        font-weight:bold;}
span.Heading2Char
        {mso-style-name:"Heading 2 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 2";
        font-family:"Verdana",sans-serif;
        color:black;}
span.Heading3Char
        {mso-style-name:"Heading 3 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 3";
        font-family:"Verdana",sans-serif;
        color:black;}
span.Heading4Char
        {mso-style-name:"Heading 4 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 4";
        font-family:"Verdana",sans-serif;
        color:black;}
span.Heading5Char
        {mso-style-name:"Heading 5 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 5";
        font-family:"Verdana",sans-serif;
        color:black;}
span.Heading6Char
        {mso-style-name:"Heading 6 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 6";
        font-family:"Verdana",sans-serif;
        color:black;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle24
        {mso-style-type:personal-compose;
        font-family:"Verdana",sans-serif;
        color:#001A6C;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body bgcolor="white" lang="EN-US" link="#339933" vlink="#996600">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C">I’ve been fighting this error for a couple of years now and just when I think I’ve got it understood and “Fixed”, it bites me again.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C">Here’s the error:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">Exception ignored in: <function Variable.__del__ at 0x0000016CA840C9D0><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">Traceback (most recent call last):<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">  File "X:\Python\python3.8\lib\tkinter\__init__.py", line 351, in __del__<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">    if self._tk.getboolean(self._tk.call("info", "exists", self._name)):<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">RuntimeError: main thread is not in main loop<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">Exception ignored in: <function Variable.__del__ at 0x0000016CA840C9D0><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">Traceback (most recent call last):<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">  File "X:\Python\python3.8\lib\tkinter\__init__.py", line 351, in __del__<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">    if self._tk.getboolean(self._tk.call("info", "exists", self._name)):<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">RuntimeError: main thread is not in main loop<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">Exception ignored in: <function Variable.__del__ at 0x0000016CA840C9D0><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">Traceback (most recent call last):<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">  File "X:\Python\python3.8\lib\tkinter\__init__.py", line 351, in __del__<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">    if self._tk.getboolean(self._tk.call("info", "exists", self._name)):<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">RuntimeError: main thread is not in main loop<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">Exception ignored in: <function Image.__del__ at 0x0000016CA8446310><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">Traceback (most recent call last):<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">  File "X:\Python\python3.8\lib\tkinter\__init__.py", line 4014, in __del__<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">    self.tk.call('image', 'delete', self.name)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">RuntimeError: main thread is not in main loop<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;font-family:"Courier New";color:#001A6C">Tcl_AsyncDelete: async handler deleted by the wrong thread<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C">It happens in programs that are multi-threaded.  The threads do NOT make any tkinter calls and do not touch any variable that has anything to do with tkinter.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C">What appears to be happening is that tkinter objects are marked to be deleted and then when Python’s garbage collect runs and actually does the deletes, it is happening in the context of the
 thread, not the main thread.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C">My way around this at the moment is to keep the widgets around for the duration of the program rather than deleting them in any way.  I would really like to get this solved though as other people
 using my code run into this and don’t know what to do.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C">Any ideas on how to dispose of widgets / windows in a way that immediately calls these delete methods? Or is it possible to tell tkinter that despite the deletes being called from another thread
 it’s OK because the thread isn’t actually changing anything at the same time as the main thread?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C">Thank you<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:13.0pt;color:#001A6C">-mike<o:p></o:p></span></p>
</div>
</body>
</html>