[Tutor] Tkinter canvas movement question...
alan.gauld@bt.com
alan.gauld@bt.com
Thu, 23 Aug 2001 16:55:51 +0100
------_=_NextPart_001_01C12BEC.157463B0
Content-type: text/plain; charset="ISO-8859-1"
Hi welcome to the posting community :-)
class dude:
def __init__(self):
self.physical = screen.create_oval(30,270,60,300, fill='white',
outline='white')
def left(self):
screen.move(self.physical, 5, 5)
circle = dude()
root.bind_all('<Left>', circle.left())
Try:
root.bind_all('<Left>',circle.left)
Although I've never used bind_all and I'm not entirely convinced about
assigning a bound method like this, I'm not sure what gets passed
as the self argument..
...Any ideas why that wont work?
It doesn't work because of the parens. You are calling the
method instead of passing it as an object. Thats also why
the circle has already moved left...
HTH,
Alan g
------_=_NextPart_001_01C12BEC.157463B0
Content-type: text/html; charset="ISO-8859-1"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META content="MSHTML 5.00.3013.2600" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN
class=140005415-23082001>Hi welcome to the posting community
:-)</SPAN></FONT></DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
<DIV><FONT face=Arial size=2>class dude:<BR> def
__init__(self):<BR> self.physical =
screen.create_oval(30,270,60,300, fill='white',
outline='white')<BR> def
left(self):<BR>
screen.move(self.physical, 5, 5)</FONT></DIV>
<DIV><FONT size=2><FONT face=Arial><SPAN class=140005415-23082001><FONT
color=#0000ff face="Courier New"> </FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT size=2><FONT face=Arial><SPAN
class=140005415-23082001> </SPAN>circle = dude()</FONT></FONT></DIV>
<DIV><FONT face=Arial size=2>root.bind_all('<Left>',
circle.left())</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV></BLOCKQUOTE>
<DIV><FONT size=2><FONT color=#0000ff><FONT face="Courier New"><SPAN
class=140005415-23082001> </SPAN><SPAN
class=140005415-23082001> Try:</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff><FONT face="Courier New"><SPAN
class=140005415-23082001></SPAN></FONT></FONT></FONT> </DIV>
<DIV><FONT size=2><FONT color=#0000ff><FONT face="Courier New"><SPAN
class=140005415-23082001>root.bind_all('<Left>',circle.left)</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff><FONT face="Courier New"><SPAN
class=140005415-23082001></SPAN></FONT></FONT></FONT> </DIV>
<DIV><FONT size=2><FONT color=#0000ff><FONT face="Courier New"><SPAN
class=140005415-23082001>Although I've never used bind_all and I'm not entirely
convinced about</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff><FONT face="Courier New"><SPAN
class=140005415-23082001>assigning a bound method like this, I'm not sure what
gets passed </SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff><FONT face="Courier New"><SPAN
class=140005415-23082001>as the self
argument.. </SPAN></FONT></FONT></FONT> </DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
<DIV><FONT face=Arial size=2>...Any ideas why that wont work? <SPAN
class=140005415-23082001><FONT color=#0000ff
face="Courier New"> </FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=140005415-23082001></SPAN></FONT> </DIV></BLOCKQUOTE>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN
class=140005415-23082001>It doesn't work because of the parens. You are calling
the </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN
class=140005415-23082001>method instead of passing it as an object. Thats also
why </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN
class=140005415-23082001>the circle has already moved
left...</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN
class=140005415-23082001></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN
class=140005415-23082001>HTH,</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN
class=140005415-23082001></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face="Courier New" size=2><SPAN
class=140005415-23082001>Alan g</SPAN></FONT></DIV></BODY></HTML>
------_=_NextPart_001_01C12BEC.157463B0--