[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>&nbsp;&nbsp;&nbsp; def 
  __init__(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.physical = 
  screen.create_oval(30,270,60,300, fill='white', 
  outline='white')<BR>&nbsp;&nbsp;&nbsp; def 
  left(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  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">&nbsp;</FONT></SPAN></FONT></FONT></DIV>
  <DIV><FONT size=2><FONT face=Arial><SPAN 
  class=140005415-23082001>&nbsp;</SPAN>circle = dude()</FONT></FONT></DIV>
  <DIV><FONT face=Arial size=2>root.bind_all('&lt;Left&gt;', 
  circle.left())</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV></BLOCKQUOTE>
<DIV><FONT size=2><FONT color=#0000ff><FONT face="Courier New"><SPAN 
class=140005415-23082001>&nbsp;</SPAN><SPAN 
class=140005415-23082001>&nbsp;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>&nbsp;</DIV>
<DIV><FONT size=2><FONT color=#0000ff><FONT face="Courier New"><SPAN 
class=140005415-23082001>root.bind_all('&lt;Left&gt;',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>&nbsp;</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..&nbsp;</SPAN></FONT></FONT></FONT>&nbsp;</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?&nbsp;<SPAN 
  class=140005415-23082001><FONT color=#0000ff 
  face="Courier New">&nbsp;</FONT></SPAN></FONT></DIV>
  <DIV><FONT face=Arial size=2><SPAN 
  class=140005415-23082001></SPAN></FONT>&nbsp;</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>&nbsp;</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>&nbsp;</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--