Erminio (3) [Avatar] Offline
#1
Good evening everyone, I'm studying Python and I tried the first Tkinter example in the book on my MacBook (MacOs 10.6) running Python 3.2.2 and the Tcl/Tk update recommended by the Python.org website (ActiveTcl 8.5.11. I think I entered the code correctly but after the last enter the popup shows, but it doesn't let me close the window when I press 'Goodbye' - I have to kill the process. Below the IDLE output. Any ideas, please? Thanks for your time! Erminio

Python 3.2.2 (v3.2.2:137e45f15c0b, Sep 3 2011, 17:28:59)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> from tkinter import *
>>> import sys
>>> win = Tk()
>>> button = Button(win, text = "Goodbye", command = sys.exit)
>>> button.pack()
>>> mainloop()
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
mainloop()
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/tkinter/__init__.py", line 317, in mainloop
_default_root.tk.mainloop(n)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/tkinter/__init__.py", line 1401, in __call__
raise SystemExit(msg)
SystemExit
naomi.ceder (134) [Avatar] Offline
#2
Re: TKinter first example and MacOS 10.6
Hi,

I just tried it on Mac OS 10.7 with Python 3.2 and got the same result... I'm pretty sure when I tested things on Python 3.1 it worked fine. I'm not sure what's going on, but I suspect some subtle change in the way TCL/TK is working may be behind it.

FWIW, if you open a terminal and run python3 and enter this code, it does work just fine...

In any case, you aren't doing anything wrong - this exact code USED to work just fine. If I find out anything more, I'll let you know.

Thanks for reporting the bug!

Vern
Erminio (3) [Avatar] Offline
#3
Re: TKinter first example and MacOS 10.6
Thank you for the quick answer!
Regards, Erminio
Erminio (3) [Avatar] Offline
#4
Re: TKinter first example and MacOS 10.6
FYI the same is true for listing 16.1: the first symptom something is wrong is maybe that
main_window = Tk()
creates after <ENTER> a popup window when typed into the Console while no popup appears after the same line in IDLE (no errors yet, though).

Regards, Erminio
Aetius (8) [Avatar] Offline
#5
Re: TKinter first example and MacOS 10.6
I have the same problem when running Python 3.2.3 on a Windows 7 machine.
Aetius (8) [Avatar] Offline
#6
Re: TKinter first example and MacOS 10.6
Evidently, switching out the "sys.exit" for "win.destroy" fixes the problem.
naomi.ceder (134) [Avatar] Offline
#7
Re: TKinter first example and MacOS 10.6
Hmmm.... win.destroy would work just fine, yes. I'm still not sure why sys.exit won't work though, since it's in the documentation as the standard way to exit... Oh, well...

In any case, thanks for reporting the work-around!

Cheers,
Vern
eng8ge (1) [Avatar] Offline
#8
Re: TKinter first example and MacOS 10.6
Belated further elaboration. The code as printed (with sys.exit ) does not work in a Windows 7 installation using IDLE for either Python 2.7 or 3.2. It opens a window but the window hangs when the "Goodbye" button is pressed.

Replacing sys.exit with win.destroy solves the problem. But, is this really equivalent?

Is it possible that sys.exit from the program is getting confused by sys.exit from the shell?