This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Using Turtle with IDLE on Mac OS X
Type: behavior Stage: resolved
Components: IDLE, macOS, Tkinter Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: ned.deily Nosy List: amcnerney13, belopolsky, gregorlingl, ned.deily, r.david.murray, rhettinger, ronaldoussoren
Priority: normal Keywords:

Created on 2011-01-31 05:26 by amcnerney13, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (14)
msg127577 - (view) Author: Alex McNerney (amcnerney13) Date: 2011-01-31 05:26
Info: I have Python 2.7.1:86832 (32-bit) installed using ActiveState Tcl/Tk 8.5.9 on Mac OS X 10.6

Problem:
Whenever I try to run (from the IDLE) a Python script using the turtle module, the window that shows up will draw anything passed to it, but it will not come to the front using the listen() function, nor will clicking on the window do anything more than cause the spinning beach ball to appear. Because it does not come the the foreground, functions like onkey() and onclick() are completely unusable.

However, when said Python script is run from the Terminal, the window is completely responsive. I believe this to be some sort of problem with the IDLE.app

Things that I have tried:
Tried different versions of tcl/tk: 8.4.19, 8.4.7, 8.5.9
Tried different versions of Python 2.7.1: 32-bit, 32/64-bit, 32-bit compiled from source.

Other things that may be useful:
This probably has no relevancy, but just in case:
In the .mpkg installed Python 2.7.1 (32-bit), the IDLE says the GCC version is 4.0.1
In the source compiled version, it says 4.2.1

It is quite annoying to not be able to use the IDLE to create and test programs using the turtle module. Please help.
msg127585 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-01-31 08:33
Since IDLE and the turtle modules both use Tkinter and thus are both Tcl/Tk applications, it wouldn't be surprising if you had problems trying to run a program using the IDLE module from within IDLE.  However, I find I can successfully run at least one of the supplied Turtle demos from IDLE 2.7.1 and IDLE 2.6:

  cd /Applications/Python 2.7/Extras/Demo/turtle
  idle2.7 tdemo_paint.py # or idle2.6

and with either of the two IDLE variants (32-bit -> Tk 8.4, 64-/32-bit -> Tk 8.5).  Can you supply a simple script to demonstrate the problem you see?

Keep in mind that, at the moment, neither of the standard python.org 2.7.1 installers support using ActiveState Tk 8.5.9.  The 32-bit-only installer will use ActiveState Tk 8.4, if installed, otherwise use the Apple-supplied Tk 8.4.19(?) in 10.6.  Python 2.7.1 was released before a 64-bit capable version of ActiveState Tk 8.5 was available so, as released, it will only link to the Apple-supplied Cocoa Tk 8.5.7 in 10.6 and that version has proven to be very unreliable when used with IDLE.  You should be able to build from source a Python 2.7.1 that will link to ActiveState 8.5.9 if it is present during the build but beware that there are a number of issues both major and minor that have been recently fixed in Python (and are in the current release-2.7 maintenance branch that should appear as a 2.7.2 release in the future) as well as a few issues in Cocoa Tk itself which should be fixed in an upcoming release of ActiveState Tk 8.5.
msg127586 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-01-31 08:35
er, "trying to run a program using the turtle module from within IDLE"
msg127677 - (view) Author: Alex McNerney (amcnerney13) Date: 2011-02-01 02:07
It may be because the program that I am trying to run automatically exits, I do not know yet how to keep a turtle program running (waiting for input). The only way I know so far is to use the function "exitonclick()," but when using that, my I cannot use any other mouseevents in my program. (Help?) Anyways, an example of a script that will cause turtle to hang/crash is even such a simple one as:
"
import turtle as t
def flfr():
    t.fd(10)
    t.lt(45)
    t.fd(10)
    t.rt(45)
t.onkey(flfr, "Up")
t.listen()
"
Is there anyway to keep a turtle program running, waiting for user interaction without using the exitonclick() function? Also, thank you for pointing out the maintenance svn, I did an svn checkout, compiled, and installed it and it fixed other problems that I was having with Python 2.7.1 ActiveState Tcl/Tk 8.5.9 (such as hanging when running a program when the shell isn't open.)

Another quick question that you don't have to answer: is there anyway to ignore interaction (keystrokes, mouseclicks) while an onkey function is activated? Like if I make a function that takes 10 seconds to complete, can I ignore all interaction while that function is being run?

Thank you for your time.
msg127678 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-02-01 02:28
Well, the bug tracker isn't really the place to get help on using Python.  I would suggest posting to python-list, you are more likely to find people with the time to help you there.  You should also take a look at the Turtle demo programs, I'm pretty sure you can find your answers there as I know some of them are interactive.

Turtle is designed to work from IDLE, so if it doesn't it's a bug.

You haven't mentioned an actual crash of the python interpreter, so I'm changing the type to behavior.
msg127687 - (view) Author: Alex McNerney (amcnerney13) Date: 2011-02-01 08:37
Sorry to keep bothering, but running Python 2.7.1:88286 (maintenance) on ActiveState Tcl/Tk 8.5.9 causes the idle to hang when a simple script like:
"
x = raw_input("x: ")
print x
"
is run. Is this a bug in Tcl/Tk? Looking in the logs I see several instances of "setCanCycle: is deprecated.  Please use setCollectionBehavior instead" Does this have any relevancy?

Relating to this, I don't know if it is proper to ask here, but is it possible to link Python to a specific Tcl/Tk when compiling from the source?

Note: When running Python 2.7.1 (32-bit from installer) with Tcl/Tk 8.4, the above problem is not there.
msg127689 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-02-01 10:46
Now that I looked at the documentation (http://docs.python.org/library/turtle.html), I see that it is clear that Turtle is designed to work from IDLE *but*, as is noted, "when using the module from within IDLE run with the -n switch", which means run IDLE without a subprocess.  What may not be so obvious is how to do that on Mac OS X.  Double-clicking on IDLE.app launches it with default values including a subprocess and there is no straightforward to override those.  From a terminal shell, it is easy to start bin/idle:

   $ idle2.7 -n

although that has a few cosmetic disadvantages with bin/idle over IDLE.app (for example, the application name displayed is "Python" not "IDLE").  It has aways been possible to launch an OS X GUI app from a shell command line using the open(1) command; as of OS X 10.6 it is now also possible to pass regular command line arguments to the application.  So the following would work in 10.6 and probably be preferable:

   $ open -a "/Applications/Python 2.7/IDLE.app" --args -n

If you want to have a double-clickable application, a simple approach is to create a launcher application with AppleScript:

   $ osacompile -o 'IDLE-n.app' <<EOF
   > do shell script "open -a '/Applications/Python 2.7/IDLE.app' --args -n"
   > EOF

As someone not used to using Turtle and given the intended user base for Turtle, I wonder whether the current Turtle module documentation is sufficient on this point.  Two possible actions I could see are: (1) expanding the documentation to include a suggestion like the above to allow for an OS X clickable app; and/or (2) actually supplying such a simple no-subprocess app with the standard python.org installer distribution (or some other solution).  How is this issue handled on Windows?  Is there a need to expand the documentation in general?
(adding Raymond to the nosy list)
msg127692 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-02-01 11:13
[Please don't add new topics to the same tracker issue.  As David mentioned, it would be better to ask for help on one of the user lists to be sure before opening an issue.  Besides the general python-list, there is an active OS X users list (pythonmac-sig) where you will find users of IDLE;  see http://www.python.org/community/sigs/

That said, to address your most recent message, that appears to indeed be a problem.  I've opened Issue11088 for it.  The "setCanCycle: is deprecated" messages are a harmless artifact; they should disappear in an upcoming maintenance release of ActiveState Tcl 8.5.]
msg127696 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-02-01 13:16
Ned: I read the bits in the turtle docs about -n as meaning *if* you use -n *then* you should set this profile option (but if you don't, things should work).  I didn't go over the docs in detail, though, so maybe I'm misreading.  Since you and I clearly don't know what we are talking about in detail, I'm adding Gregor and Alexander (the latter since he's clearly been using it) to nosy.
msg127697 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-02-01 13:17
It's clear from testing it and from some searches that -n is, in fact, required.
msg127700 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-02-01 14:13
Ah, in that case I think the docs could be improved on that point.
msg127702 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-02-01 14:21
I saw this post by Gregor: http://thread.gmane.org/gmane.comp.python.general/334881/focus=334996

I don't know applicable it still is on Windows.  But it does seem to be still true on OS X.
msg127716 - (view) Author: Alex McNerney (amcnerney13) Date: 2011-02-02 03:38
Thank you so much for pointing out the -n option!
Hopefully the Tk 8.5.9 input issue will be solved soon enough.
Thank you both again.
I'm not sure if I'm supposed to or not, but I am marking this as closed – seeing as the main issue has been solved.
msg127717 - (view) Author: Alex McNerney (amcnerney13) Date: 2011-02-02 03:39
solved* or rather, a workaround has been found.
History
Date User Action Args
2022-04-11 14:57:12adminsetgithub: 55284
2011-02-02 07:40:13ned.deilysetassignee: ned.deily
resolution: works for me
nosy: rhettinger, ronaldoussoren, belopolsky, gregorlingl, ned.deily, r.david.murray, amcnerney13
stage: resolved
2011-02-02 03:39:33amcnerney13setnosy: rhettinger, ronaldoussoren, belopolsky, gregorlingl, ned.deily, r.david.murray, amcnerney13
messages: + msg127717
2011-02-02 03:38:35amcnerney13setstatus: open -> closed
nosy: rhettinger, ronaldoussoren, belopolsky, gregorlingl, ned.deily, r.david.murray, amcnerney13
messages: + msg127716
2011-02-01 14:21:55ned.deilysetnosy: rhettinger, ronaldoussoren, belopolsky, gregorlingl, ned.deily, r.david.murray, amcnerney13
messages: + msg127702
2011-02-01 14:13:22r.david.murraysetnosy: rhettinger, ronaldoussoren, belopolsky, gregorlingl, ned.deily, r.david.murray, amcnerney13
messages: + msg127700
2011-02-01 13:17:08ned.deilysetnosy: rhettinger, ronaldoussoren, belopolsky, gregorlingl, ned.deily, r.david.murray, amcnerney13
messages: + msg127697
2011-02-01 13:16:05r.david.murraysetassignee: ned.deily -> (no value)

messages: + msg127696
nosy: + gregorlingl, belopolsky
2011-02-01 11:13:06ned.deilysetnosy: rhettinger, ronaldoussoren, ned.deily, r.david.murray, amcnerney13
messages: + msg127692
2011-02-01 10:46:49ned.deilysetnosy: + rhettinger
title: Turtle crash with IDLE on Mac OS X 10.6 -> Using Turtle with IDLE on Mac OS X
messages: + msg127689

versions: + Python 3.2
2011-02-01 08:37:00amcnerney13setnosy: ronaldoussoren, ned.deily, r.david.murray, amcnerney13
messages: + msg127687
2011-02-01 02:28:11r.david.murraysettype: crash -> behavior

messages: + msg127678
nosy: + r.david.murray
2011-02-01 02:07:06amcnerney13setnosy: ronaldoussoren, ned.deily, amcnerney13
messages: + msg127677
2011-01-31 08:35:07ned.deilysetnosy: ronaldoussoren, ned.deily, amcnerney13
messages: + msg127586
2011-01-31 08:33:02ned.deilysetassignee: ronaldoussoren -> ned.deily

messages: + msg127585
nosy: + ned.deily
2011-01-31 05:26:32amcnerney13create