Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32884
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'none:': 0.05; 'bug.': 0.07; 'turtle': 0.07; 'python': 0.09; 'events.': 0.09; 'happens.': 0.09; 'item,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'bug': 0.10; 'def': 0.10; '1.1b': 0.16; 'feature?': 0.16; 'item:': 0.16; 'list):': 0.16; 'nicolas': 0.16; 'num)': 0.16; 'polygon': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'subject:turtle': 0.16; 'wrote:': 0.17; 'shape': 0.17; 'windows': 0.19; 'import': 0.21; 'file:': 0.22; 'seems': 0.23; 'patch': 0.24; 'url:bugs': 0.24; 'header:User-Agent:1': 0.26; 'module.': 0.27; "doesn't": 0.28; 'header:X-Complaints-To:1': 0.28; 'skip:( 20': 0.28; 'run': 0.28; 'skip:_ 10': 0.29; 'skip:- 30': 0.31; 'gets': 0.32; 'url:python': 0.32; 'running': 0.32; 'problem': 0.33; 'to:addr:python-list': 0.33; 'version': 0.34; 'received:org': 0.36; 'url:org': 0.36; '(i.e.': 0.36; 'test': 0.36; 'item': 0.37; 'subject:: ': 0.38; 'skip:( 30': 0.38; 'nothing': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'red': 0.60; 'side': 0.61; 'fun': 0.64; 'here': 0.65; 'believe': 0.69; 'square': 0.75; 'click': 0.76 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: clicking on turtle |
| Date | Wed, 07 Nov 2012 13:54:05 +0100 |
| Organization | None |
| References | <201211062109.qA6L9IvA006105@hydra.calcul> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p50849829.dip.t-dialin.net |
| User-Agent | KNode/4.7.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3368.1352292858.27098.python-list@python.org> (permalink) |
| Lines | 69 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1352292858 news.xs4all.nl 6907 [2001:888:2000:d::a6]:39034 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:32884 |
Show key headers only | View raw
Nicolas Graner wrote:
> I have a problem with the standard "turtle" module. When a turtle has
> a custom shape of type "compound", it doesn't seem to respond to click
> events. No problem with polygon shapes.
>
> Running python 3.2.3, turtle version 1.1b on Windows XP.
>
> Here is my test file:
>
> ##################################################
> import turtle
> square = ((0,0),(0,20),(20,20),(20,0))
> turtle.addshape("sq1", square) # sq1 = polygon shape
> s = turtle.Shape("compound")
> s.addcomponent(square, "red")
> turtle.addshape("sq2", s) # sq2 = compound shape
> t1 = turtle.Turtle(shape="sq1")
> t2 = turtle.Turtle(shape="sq2")
> t2.fd(20) # set the turtles side by side
> def click(x,y): print("click at",x,y)
> t1.onclick(click)
> t2.onclick(click)
> turtle.mainloop()
> ##################################################
>
> When I run this and click on the black square (i.e. t1), the message
> "click at..." gets printed on the console. When I click on the red
> square (i.e. t2), nothing happens.
>
> Bug or feature?
I believe it's a bug. Please report it on http://bugs.python.org
As a quick-fix here's a monkey patch that seems to work:
import turtle
def _onclick(self, item, fun, num=1, add=None):
if isinstance(item, list):
for item in item:
self._onclick(item, fun, num, add)
return
if fun is None:
self.cv.tag_unbind(item, "<Button-%s>" % num)
else:
def eventfun(event):
x, y = (self.cv.canvasx(event.x)/self.xscale,
-self.cv.canvasy(event.y)/self.yscale)
fun(x, y)
self.cv.tag_bind(item, "<Button-%s>" % num, eventfun, add)
turtle.TurtleScreenBase._onclick = _onclick
square = ((0,0),(0,20),(20,20),(20,0))
turtle.addshape("sq1", square) # sq1 = polygon shape
s = turtle.Shape("compound")
s.addcomponent(square, "red")
turtle.addshape("sq2", s) # sq2 = compound shape
t1 = turtle.Turtle(shape="sq1")
t2 = turtle.Turtle(shape="sq2")
t2.fd(20) # set the turtles side by side
def click(x,y): print("click at",x,y)
t1.onclick(click)
t2.onclick(click)
turtle.mainloop()
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: clicking on turtle Peter Otten <__peter__@web.de> - 2012-11-07 13:54 +0100
csiph-web