Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turtle Graphics RawTurtle problem #66364

Closed
KentDLee mannequin opened this issue Aug 8, 2014 · 5 comments
Closed

Turtle Graphics RawTurtle problem #66364

KentDLee mannequin opened this issue Aug 8, 2014 · 5 comments
Assignees

Comments

@KentDLee
Copy link
Mannequin

KentDLee mannequin commented Aug 8, 2014

BPO 22168
Nosy @ned-deily
Files
  • c4.py
  • issue22168.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/ned-deily'
    closed_at = <Date 2014-09-14.07:05:33.357>
    created_at = <Date 2014-08-08.01:27:43.349>
    labels = ['expert-tkinter']
    title = 'Turtle Graphics RawTurtle problem'
    updated_at = <Date 2014-09-14.07:05:33.356>
    user = 'https://bugs.python.org/KentDLee'

    bugs.python.org fields:

    activity = <Date 2014-09-14.07:05:33.356>
    actor = 'ned.deily'
    assignee = 'ned.deily'
    closed = True
    closed_date = <Date 2014-09-14.07:05:33.357>
    closer = 'ned.deily'
    components = ['Tkinter']
    creation = <Date 2014-08-08.01:27:43.349>
    creator = 'Kent.D..Lee'
    dependencies = []
    files = ['36307', '36447']
    hgrepos = []
    issue_num = 22168
    keywords = ['patch']
    message_count = 5.0
    messages = ['225049', '225053', '225054', '225776', '226863']
    nosy_count = 2.0
    nosy_names = ['ned.deily', 'Kent.D..Lee']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue22168'
    versions = ['Python 3.4', 'Python 3.5']

    @KentDLee
    Copy link
    Mannequin Author

    KentDLee mannequin commented Aug 8, 2014

    This is either a turtle graphics or tkinter problem.

    In Python 3.4 it appears that something in Turtle Graphics broke or at least changed. I get the following error when trying to run a program that works in Python 3.1 and 3.2.

    Kent's Mac> python3.4 c4.py
    Traceback (most recent call last):
      File "c4.py", line 283, in <module>
        main()
      File "c4.py", line 277, in main
        animApp = Connect4Application(root)
      File "c4.py", line 110, in __init__
        self.buildWindow()
      File "c4.py", line 129, in buildWindow
        theTurtle = turtle.RawTurtle(canvas)
      File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/turtle.py", line 2534, in __init__
        self.screen = TurtleScreen(canvas)
      File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/turtle.py", line 1000, in __init__
        cv._rootwindow.call('wm', 'attributes', '.', '-topmost', '1')
    AttributeError: 'Canvas' object has no attribute '_rootwindow'
    Kent's Mac> 

    The code is attached. The error occurs on line 129 when trying to create a RawTurtle and provide it with a Canvas.

    @KentDLee KentDLee mannequin added the topic-tkinter label Aug 8, 2014
    @ned-deily
    Copy link
    Member

    It looks like the changes associated with bpo-11571, released in 3.4.1, cause this problem when the program supplies its own Canvas object rather than relying on the turtle module to create a default one.

    @ned-deily ned-deily self-assigned this Aug 8, 2014
    @ned-deily
    Copy link
    Member

    As a temporary workaround, you could edit turtle.py to revert that change, in other words, just search for and delete the whole "if sys.platform == 'darwin'" test:

    diff -r d85fcf23549e Lib/turtle.py
    --- a/Lib/turtle.py     Tue Aug 05 14:02:11 2014 -0500
    +++ b/Lib/turtle.py     Thu Aug 07 19:58:25 2014 -0700
    @@ -993,12 +993,6 @@
             self._colormode = _CFG["colormode"]
             self._keys = []
             self.clear()
    -        if sys.platform == 'darwin':
    -            # Force Turtle window to the front on OS X. This is needed because
    -            # the Turtle window will show behind the Terminal window when you
    -            # start the demo from the command line.
    -            cv._rootwindow.call('wm', 'attributes', '.', '-topmost', '1')
    -            cv._rootwindow.call('wm', 'attributes', '.', '-topmost', '0')
         def clear(self):
             """Delete all drawings and all turtles from the TurtleScreen.

    The file is at /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/turtle.py.

    @ned-deily
    Copy link
    Member

    The attached patch should prevent the AttributeError exception when not using a default Canvas. I now think the overall approach introduced in bpo-11571 is not the best. I plan to commit this fix for now but encourage more robust solutions in the long term.

    @ned-deily
    Copy link
    Member

    The changesets below should prevent the problem in 3.4.2 and 3.5.0. Since there are no standard tests for turtle at the moment, there is no testcase for using a non-default Canvas but one should be added when turtle tests are (bpo-21914 and bpo-21916).

    New changset fac17d06e01d by Ned Deily in branch '3.4':
    Issue bpo-22168: Prevent turtle AttributeError with non-default Canvas on OS X.
    https://hg.python.org/cpython/rev/fac17d06e01d

    New changeset 775453a7b85d by Ned Deily in branch 'default':
    Issue bpo-22168: Prevent turtle AttributeError with non-default Canvas on OS X.
    https://hg.python.org/cpython/rev/775453a7b85d

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant