Tkinter apps won't quit except when using external run

124 views
Skip to first unread message

Lewis Levin

unread,
Apr 8, 2013, 2:14:48 PM4/8/13
to pyscr...@googlegroups.com
The following trivial tkinter (under Python 2.7.3) script won't quit when using any "Python engine" under Pyscripter:

from Tkinter import *

class MyApp:
    def __init__(self, parent):
        self.myparent = parent  # in case the parent is not root for some reason
        self.mycontainer1 = Frame(parent)
        self.mycontainer1.pack()

        self.button1 = Button(self.mycontainer1, command=self.button1click)
        self.button1.configure(text = "OK",bg='green')
        self.button1.pack(side=LEFT)
        self.button1.focus_force()

        self.button2 = Button(self.mycontainer1, text="Cancel", bg='red', command=self.button2click)
        self.button2.pack(side=RIGHT)

    def button1click(self):
        print 'button1click event handler ', 'foo ', self.button1['bg']
        if self.button1['bg'] == 'green':
            self.button1['bg'] = 'yellow'
        else:
            self.button1['bg'] = 'green'

    def button2click(self):
        print 'button2click event handler'
        self.myparent.quit()

root = Tk()
myapp = MyApp(root)
root.mainloop()

Note that at self.myparent.quit() the script hangs.  Repeatedly clicking on its close box brings up the Windows dialog for hangs, asking if you want to kill the app (the python interpreter in this case).

Pyscripter output console shows the following errors:

>>> Traceback (most recent call last):
  File "C:\Program Files (x86)\PyScripter\Lib\rpyc.zip\rpyc\core\netref.py", line 196, in __call__
  File "C:\Program Files (x86)\PyScripter\Lib\rpyc.zip\rpyc\core\netref.py", line 71, in syncreq
  File "C:\Program Files (x86)\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 429, in sync_request
  File "C:\Program Files (x86)\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 229, in _send_request
  File "C:\Program Files (x86)\PyScripter\Lib\rpyc.zip\rpyc\core\protocol.py", line 224, in _send
  File "C:\Program Files (x86)\PyScripter\Lib\rpyc.zip\rpyc\core\channel.py", line 69, in send
  File "C:\Program Files (x86)\PyScripter\Lib\rpyc.zip\rpyc\core\stream.py", line 181, in write
EOFError: [Errno 10054] An existing connection was forcibly closed by the remote host
 

I should point out that Spyder, WingIDE, and Sublime Text (python build command) don't exhibit any difficulty.  The script stops and control returns to the IDE or editor.

I would like to use Pyscripter, but I have to modify the source to be Pyscripter specific, which should not be needed.

I can use external run as that works. It is just not clear to me why I need to do it.

Lewis Levin

unread,
Apr 8, 2013, 3:14:31 PM4/8/13
to pyscr...@googlegroups.com
OK.  Now I get it.  Have to re-initialize.  But, why?  I thought since v 2. 0 of Pyscripter the reinitialize happened automatically.

Can it be set to do that.  If one is really using the debugger (as opposed to merely running a script) presumably you have breakpoints or are stepping so the stop at the end isn't absolutely necessary.

Lewis Levin

unread,
Apr 8, 2013, 3:21:03 PM4/8/13
to pyscr...@googlegroups.com

Note:  I DO have reinitialize before run set to True in IDE options.
Reply all
Reply to author
Forward
0 new messages