Python turtle ondrag event vs. compound shapes


When I register a polygon, or a compound shape with only a single component, I'm able to create a turtle cursor using that shape, add a drag event handler, and drag it around the screen.

But when I register a compound shape with a second component, I can no longer drag it:

from turtle import Turtle, Screen, Shape def simple_polygon(turtle): turtle.begin_poly() turtle.circle(50) turtle.end_poly() screen.register_shape("simple_polygon", turtle.get_poly()) turtle.reset() def compound_single(turtle): shape = Shape("compound") turtle.begin_poly() turtle.circle(50) turtle.end_poly() shape.addcomponent(turtle.get_poly(), "blue", "blue") # component #1 screen.register_shape("compound_single", shape) turtle.reset() def compound_double(turtle): shape = Shape("compound") turtle.begin_poly() turtle.circle(50) turtle.end_poly() shape.addcomponent(turtle.get_poly(), "green", "green") # component #1 turtle.penup() turtle.left(90) turtle.forward(25) turtle.right(90) turtle.pendown() turtle.begin_poly() turtle.circle(25) turtle.end_poly() shape.addcomponent(turtle.get_poly(), "yellow", "yellow") # component #2 screen.register_shape("compound_double", shape) turtle.reset() def drag_handler(turtle, x, y): turtle.ondrag(None) # disable ondrag event inside drag_handler turtle.goto(x, y) turtle.ondrag(lambda x, y, turtle=turtle: drag_handler(turtle, x, y)) screen = Screen() magic_marker = Turtle() simple_polygon(magic_marker) compound_single(magic_marker) compound_double(magic_marker) magic_marker.hideturtle() red = Turtle(shape="simple_polygon") red.color("red") red.penup() red.goto(150, 150) red.ondrag(lambda x, y: drag_handler(red, x, y)) blue = Turtle(shape="compound_single") blue.penup() blue.goto(-150, -150) blue.ondrag(lambda x, y: drag_handler(blue, x, y)) mostly_green = Turtle(shape="compound_double") mostly_green.penup() mostly_green.goto(150, -150) mostly_green.ondrag(lambda x, y: drag_handler(mostly_green, x, y)) screen.mainloop()

You'll find that only two of the three shapes generated can be dragged. Comment out this line:

shape.addcomponent(turtle.get_poly(), "yellow", "yellow") # component #2

and the third circle will be all green and become draggable.

I can't find any mention in the turtle documentation about compound shapes with mutiple components not being valid cursors as far as dragging. It doesn't make any difference whether the second component is completely within, overlapping or outside the first.

Looking at the turtle code, I see no distinction, leading me to believe that this problem is in the tkinter underpinning and not documented properly in turtle. Is this problem Unix or OSX specific?

Am I missing something? Why can't I drag cursors built out of multiple components?


I think what's going on is when you drag one object, the whole canvas moves and it looks like it's moving.

The same thing happens in Canvas Tkinter. When you program something to happen when you click an object, the whole canvas is waiting for a click. SO that means if two objects have a onclick event, the whole thing won't work.

Hope this helps!!



  • oracle
  • How to call a method from a separate class java
  • Stop CTRL-Click from affecting parent datagrid
  • Set confirmation prompt box's title
  • Toggling ProxyCreation in EF7 under new configuration
  • Effectively searching through entire 1 level nested JSONB in Postgres
  • JQuery: Visual studio, error CS1056: Unexpected character '$'
  • How do I sendBroadcast(intent) from myDialog and receive in myActivity?
  • Trigger Xamarin.Forms Picker
  • How to sort the output of “grep -l” chronologically by newest modification date last?
  • Using external third-party properties file with Spring Boot Fat Jar
  • Is it Possible to get results of AsyncTask as an Arraylist Hashmap
  • Problem with Ruby + rtaglib gem
  • Oracle MERGE: only NOT MATCHED is triggered
  • Azure deployment virtual directory [duplicate]
  • How to capture if current vendor is selected
  • Passing integer variable from jsp to servlet
  • starting headless firefox with Xvfb does not work
  • Android: Saving an image to directory
  • cc1plus: unrecognized command line option warning on any other warning
  • DB2 Unique Constraint over multiple Columns
  • Dynamically create controls in android using Kotlin
  • How do I get partial cell styling in excel using EPpplus?
  • Mysql setting default value to be items auto increment key
  • Simulate onFling() programmatically instead of detecting it (Android)
  • Upload synthesized speech from firebase function node.js server's tmp directory
  • Cannot get Django 1.7 Migrations to detect proper changes to my DB.
  • Web scraping pdf files from HTML
  • mssql script data insert or update
  • jQuery colorbox breaks postbacks in ASP.NET Web Forms
  • opencv deskewing a contour
  • Add checkbox dynamically using angular 2
  • how to specify different css for ie
  • how to run a different select statement based on condition in Hive SQL
  • Drag and drop unicode TText in DelphiXe4