Skip to content Skip to sidebar Skip to footer

Tkinter.tk() And Threading

There is an interesting issue with Tkinter and threading: I have a Tkinter based GUI and some code executed alongside mainloop. It works like charm if I only do it once. But if i d

Solution 1:

It works fine for me (OS X 10.7, Python 2.7.1) so maybe it's related to your installation:

pu@pumbair:~/Downloads$pythontest.py2012-07-05 19:22:19,673INFO:---------1---------2012-07-05 19:22:19,673INFO:StartingGUI2012-07-05 19:22:19,674INFO:Dosomethingalongsideguy2012-07-05 19:22:19,918INFO:Waitforguitoterminate2012-07-05 19:22:19,918INFO:SetupGUI2012-07-05 19:22:20,422INFO:Mainloopisover2012-07-05 19:22:20,424INFO:threadterminated2012-07-05 19:22:20,424INFO:---------2---------2012-07-05 19:22:20,425INFO:StartingGUI2012-07-05 19:22:20,459INFO:Dosomethingalongsidegui2012-07-05 19:22:20,459INFO:SetupGUI2012-07-05 19:22:20,459INFO:Waitforguitoterminate2012-07-05 19:22:20,962INFO:Mainloopisover2012-07-05 19:22:20,965INFO:threadterminatedpu@pumbair:~/Downloads$pythonPython2.7.1(r271:86832,Jun252011,05:09:01) 
[GCC4.2.1(BasedonAppleInc.build5658)(LLVMbuild2335.15.00)] ondarwinType"help","copyright","credits"or"license"formoreinformation.>>>

but operations do not always execute in the same order, of course (compare this with above):

pu@pumbair:~/Downloads$pythontest.py2012-07-05 19:27:17,827INFO:---------1---------2012-07-05 19:27:17,827INFO:StartingGUI2012-07-05 19:27:17,827INFO:Dosomethingalongsidegui2012-07-05 19:27:17,937INFO:SetupGUI2012-07-05 19:27:17,938INFO:Waitforguitoterminate2012-07-05 19:27:18,440INFO:Mainloopisover2012-07-05 19:27:18,442INFO:threadterminated2012-07-05 19:27:18,443INFO:---------2---------2012-07-05 19:27:18,443INFO:StartingGUI2012-07-05 19:27:18,478INFO:Dosomethingalongsidegui2012-07-05 19:27:18,478INFO:SetupGUI2012-07-05 19:27:18,479INFO:Waitforguitoterminate2012-07-05 19:27:18,981INFO:Mainloopisover2012-07-05 19:27:18,982INFO:threadterminated

On 10.6.8 with Python 2.6.1 it also works, but with strange messages:

symacbook:Downloadsputest$pythontest.py2012-07-05 21:33:49,844INFO:---------1---------2012-07-05 21:33:49,844INFO:StartingGUI2012-07-05 21:33:49,844INFO:Dosomethingalongsidegui2012-07-05 21:33:52,356INFO:Waitforguitoterminate2012-07-05 21:33:52,356INFO:SetupGUI2012-07-05 21:33:52,858INFO:Mainloopisover2012-07-05 21:33:52,859INFO:threadterminated2012-07-05 21:33:52,860INFO:---------2---------2012-07-05 21:33:52,860INFO:StartingGUI2012-07-05 21:33:52,892INFO:SetupGUI2012-07-05 21:33:52,892INFO:Dosomethingalongsidegui2012-07-05 21:33:52,894INFO:Waitforguitoterminate2012-07-05 21:33:52.894 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002d9d90ofclassNSCFArrayautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.896 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002d51e0ofclassNSFontautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.897 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x7fff70737588ofclassNSCFStringautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.897 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x101233b40ofclass_NSThemeCloseWidgetautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.898 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e0ef0ofclassNSCFArrayautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.898 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002d51e0ofclassNSFontautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.899 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x7fff70737588ofclassNSCFStringautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.899 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e1170ofclass_NSThemeWidgetautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.899 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x10120e9c0ofclassNSCFArrayautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.900 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002d51e0ofclassNSFontautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.900 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x7fff70737588ofclassNSCFStringautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.901 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e1710ofclass_NSThemeWidgetautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.901 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e18e0ofclassNSCFArrayautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.902 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1012343e0ofclassNSTrackingAreaautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.902 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x101234010ofclassNSTrackingAreaautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.903 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e1910ofclassNSViewautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.904 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002d3550ofclassNSCFArrayautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.905 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e1910ofclassNSViewautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.905 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x101234840ofclassNSCFArrayautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.906 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e1d90ofclassNSCFArrayautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.906 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x101234870ofclass__NSFastEnumerationEnumeratorautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.907 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x101233b40ofclass_NSThemeCloseWidgetautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.907 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x101233b40ofclass_NSThemeCloseWidgetautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.908 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e1710ofclass_NSThemeWidgetautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.908 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e1710ofclass_NSThemeWidgetautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.908 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e1170ofclass_NSThemeWidgetautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.909 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e1170ofclass_NSThemeWidgetautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.909 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e22e0ofclassNSTrackingAreaautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.910 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e24d0ofclassNSConcreteAttributedStringautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.911 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x7fff70737588ofclassNSCFStringautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.911 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002d51e0ofclassNSFontautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.911 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002d91f0ofclassNSFontautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.912 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x7fff70737588ofclassNSCFStringautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.912 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e28b0ofclassNSTrackingAreaautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.913 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e3ab0ofclassNSConcreteMapTableautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.914 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e3e30ofclassNSCFArrayautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.915 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e1dc0ofclassNSObjectautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.915 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e4120ofclassNSCFArrayautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.916 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x101234a60ofclassNSMenuItemautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.916 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002ac2e0ofclassNSCFNumberautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.916 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e4180ofclassNSCFDictionaryautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.917 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x10120e770ofclassNSCFNumberautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.917 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1012031d0ofclassNSCFDictionaryautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.918 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x101233b40ofclass_NSThemeCloseWidgetautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.919 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x101233b40ofclass_NSThemeCloseWidgetautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.919 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e1710ofclass_NSThemeWidgetautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.919 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e1710ofclass_NSThemeWidgetautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.920 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e1170ofclass_NSThemeWidgetautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:52.920 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e1170ofclass_NSThemeWidgetautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:53.393 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x101236910ofclassNSCFArrayautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:53.393 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x10120e770ofclassNSCFNumberautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:53.394 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x101236ce0ofclassNSCFDictionaryautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:53.394 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002e24b0ofclassNSCFStringautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:53.395 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x1002ac2e0ofclassNSCFNumberautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:53.395 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x101236d20ofclassNSCFDictionaryautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:53.396 Python[1281:3407]***__NSAutoreleaseNoPool():Object0x101236e70ofclassNSCFArrayautoreleasedwithnopoolinplace-justleaking2012-07-05 21:33:53,398INFO:Mainloopisover2012-07-05 21:33:53,400INFO:threadterminated

Post a Comment for "Tkinter.tk() And Threading"