[Tutor] Little questions !

Fabian Wissing fabwing@math.uni-muenster.de
Tue, 23 May 2000 22:49:43 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_0004_01BFC509.2FDC2F80
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hallo !

I hope it is possible to solve my problems with programming python.
*1: What can I do to send arguments with "command"  to another method, =
without calling the method immediately. But after activating the button.
*2: IWhy can I not do this ? (Error with the Index) How is it possible ?
Thanks Fabian
(fabwing@uni-muenster.de) =20
import Tkinter

class XXX (Tkinter.Frame):
=20
 rows =3D 8
 columns =3D 8
=20
 def __init__(self, root):=20
  Tkinter.Frame.__init__ (self, root)
  self.butt =3D []
  self.butt =3D [self.butt]*self.rows
  for row in range (self.rows):
   self.butt [row] =3D [self.butt] * self.columns
   for column in range (self.columns):
           self.butt [row][column] =3D Tkinter.Button(text =3D 'xxx', =
background =3D 'white', command =3D self.surrounding(row, column)) *1
    self.butt [row][column].grid(row=3Drow, column=3Dcolumn)
 =20
=20
 def surrounding (self, row, column):    ## I know this is not a good =
algorithem
 =20
  if row =3D=3D 0:
   if column =3D=3D 0:
    self.change (0, 1)
    self.change (1, 0)
    self.change (1, 1)
   elif column =3D=3D self.columns:
    self.change (0, 2)
    self.change (1, 2)
    self.change (1, 3)
   else:
    self.change (0, column-1)
    self.change (0, column+1)
    self.change (1, column-1)
    self.change (1, column)
    self.change (1, column+1)
  elif row =3D=3D self.rows:
   if column =3D=3D 0:
    self.change (row-1, 0)
    self.change (row-1, 1)
    self.change (row, 1)
   elif column =3D=3D self.columns:
    self.change (row, column-1)
    self.change (row-1, column-1)
    self.change (row-1, column)
   else:
    self.change (row, column-1)
    self.change (row-1, column-1)
    self.change (row-1, column)
    self.change (row-1, column+1)
    self.change (row, column+1)
  else:
   if column =3D=3D 0:
    self.change (row-1, column)
    self.change (row-1, column+1)
    self.change (row, column+1)
    self.change (row+1, column+1)
    self.change (row+1, column)
   elif column =3D=3D self.columns:
    self.change (row+1, column)
    self.change (row+1, column-1)
    self.change (row, column-1)
    self.change (row-1, column-1)
    self.change (row-1, column)
   else:
    self.change (row+1, column)
    self.change (row+1, column-1)
    self.change (row, column-1)
    self.change (row-1, column-1)
    self.change (row-1, column)
    self.change (row-1, column+1)
    self.change (row, column+1)
    self.change (row+1, column+1)
=20
 def change (self, row, column):
  ##if self.butt [row] [column] ["background" =3D=3D "white"]: *2=20
  ## self.butt [row] [column] ["background"] =3D "black"
  ##else:
  ## self.butt [row] [column] ["background"] =3D "white"
  print row, column ##only example
def main ():
 app =3D XXX (Tkinter.Tk())
 app.pack()
 app.mainloop()
if __name__ =3D=3D '__main__':
 main()

------=_NextPart_000_0004_01BFC509.2FDC2F80
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.72.3110.7"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#fffff0>
<DIV><FONT color=3D#000000 face=3DArial size=3D2><FONT =
color=3D#000000><STRONG>Hallo=20
!</FONT></FONT><FONT color=3D#000000></FONT></STRONG></DIV>
<DIV><FONT face=3DArial size=3D2><FONT =
color=3D#000000><STRONG></FONT></FONT><FONT=20
color=3D#000000></FONT></STRONG>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><FONT color=3D#000000><STRONG>I hope it =
is possible=20
to solve my problems with programming python.</FONT></FONT><FONT=20
color=3D#000000></FONT></STRONG></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT color=3D#000000 =
face=3DArial=20
size=3D2><STRONG>*1: What can I do to send arguments with=20
&quot;command&quot;&nbsp; to another method, without calling the method=20
immediately. But after activating the button.</FONT></STRONG></DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2><STRONG>*2: IWhy can I =
not do this ?=20
(Error with the Index) How is it possible ?</FONT></STRONG></DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2><STRONG>Thanks=20
Fabian</FONT></STRONG></DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2><A=20
href=3D"mailto:(fabwing@uni-muenster.de"><STRONG>(fabwing@uni-muenster.de=
</A>)&nbsp;=20
</FONT></STRONG></DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2>import =
Tkinter</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2>class XXX=20
(Tkinter.Frame):<BR>&nbsp;<BR>&nbsp;rows =3D 8<BR>&nbsp;columns =3D=20
8<BR>&nbsp;<BR>&nbsp;def __init__(self, root): <BR>&nbsp; =
Tkinter.Frame.__init__=20
(self, root)<BR>&nbsp; self.butt =3D []<BR>&nbsp; self.butt =3D=20
[self.butt]*self.rows<BR>&nbsp; for row in range =
(self.rows):<BR>&nbsp;&nbsp;=20
self.butt [row] =3D [self.butt] * self.columns<BR>&nbsp;&nbsp; for =
column in range=20
(self.columns):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;=20
self.butt [row][column] =3D Tkinter.Button(text =3D 'xxx', background =
=3D 'white',=20
<FONT color=3D#000000 face=3DArial size=3D4><STRONG>command =3D =
self.surrounding(row,=20
column)) *1</STRONG></FONT><BR>&nbsp;&nbsp;&nbsp; self.butt=20
[row][column].grid(row=3Drow, column=3Dcolumn)<BR>&nbsp; =
<BR>&nbsp;<BR>&nbsp;def=20
surrounding (self, row, column):&nbsp;&nbsp;&nbsp; ## I know this is not =
a good=20
algorithem<BR>&nbsp; <BR>&nbsp; if row =3D=3D 0:<BR>&nbsp;&nbsp; if =
column =3D=3D=20
0:<BR>&nbsp;&nbsp;&nbsp; self.change (0, 1)<BR>&nbsp;&nbsp;&nbsp; =
self.change=20
(1, 0)<BR>&nbsp;&nbsp;&nbsp; self.change (1, 1)<BR>&nbsp;&nbsp; elif =
column =3D=3D=20
self.columns:<BR>&nbsp;&nbsp;&nbsp; self.change (0, =
2)<BR>&nbsp;&nbsp;&nbsp;=20
self.change (1, 2)<BR>&nbsp;&nbsp;&nbsp; self.change (1, =
3)<BR>&nbsp;&nbsp;=20
else:<BR>&nbsp;&nbsp;&nbsp; self.change (0, =
column-1)<BR>&nbsp;&nbsp;&nbsp;=20
self.change (0, column+1)<BR>&nbsp;&nbsp;&nbsp; self.change (1,=20
column-1)<BR>&nbsp;&nbsp;&nbsp; self.change (1, =
column)<BR>&nbsp;&nbsp;&nbsp;=20
self.change (1, column+1)<BR>&nbsp; elif row =3D=3D =
self.rows:<BR>&nbsp;&nbsp; if=20
column =3D=3D 0:<BR>&nbsp;&nbsp;&nbsp; self.change (row-1, =
0)<BR>&nbsp;&nbsp;&nbsp;=20
self.change (row-1, 1)<BR>&nbsp;&nbsp;&nbsp; self.change (row,=20
1)<BR>&nbsp;&nbsp; elif column =3D=3D =
self.columns:<BR>&nbsp;&nbsp;&nbsp;=20
self.change (row, column-1)<BR>&nbsp;&nbsp;&nbsp; self.change (row-1,=20
column-1)<BR>&nbsp;&nbsp;&nbsp; self.change (row-1, =
column)<BR>&nbsp;&nbsp;=20
else:<BR>&nbsp;&nbsp;&nbsp; self.change (row, =
column-1)<BR>&nbsp;&nbsp;&nbsp;=20
self.change (row-1, column-1)<BR>&nbsp;&nbsp;&nbsp; self.change (row-1,=20
column)<BR>&nbsp;&nbsp;&nbsp; self.change (row-1,=20
column+1)<BR>&nbsp;&nbsp;&nbsp; self.change (row, column+1)<BR>&nbsp;=20
else:<BR>&nbsp;&nbsp; if column =3D=3D 0:<BR>&nbsp;&nbsp;&nbsp; =
self.change (row-1,=20
column)<BR>&nbsp;&nbsp;&nbsp; self.change (row-1,=20
column+1)<BR>&nbsp;&nbsp;&nbsp; self.change (row,=20
column+1)<BR>&nbsp;&nbsp;&nbsp; self.change (row+1,=20
column+1)<BR>&nbsp;&nbsp;&nbsp; self.change (row+1, =
column)<BR>&nbsp;&nbsp; elif=20
column =3D=3D self.columns:<BR>&nbsp;&nbsp;&nbsp; self.change (row+1,=20
column)<BR>&nbsp;&nbsp;&nbsp; self.change (row+1,=20
column-1)<BR>&nbsp;&nbsp;&nbsp; self.change (row,=20
column-1)<BR>&nbsp;&nbsp;&nbsp; self.change (row-1,=20
column-1)<BR>&nbsp;&nbsp;&nbsp; self.change (row-1, =
column)<BR>&nbsp;&nbsp;=20
else:<BR>&nbsp;&nbsp;&nbsp; self.change (row+1, =
column)<BR>&nbsp;&nbsp;&nbsp;=20
self.change (row+1, column-1)<BR>&nbsp;&nbsp;&nbsp; self.change (row,=20
column-1)<BR>&nbsp;&nbsp;&nbsp; self.change (row-1,=20
column-1)<BR>&nbsp;&nbsp;&nbsp; self.change (row-1,=20
column)<BR>&nbsp;&nbsp;&nbsp; self.change (row-1,=20
column+1)<BR>&nbsp;&nbsp;&nbsp; self.change (row,=20
column+1)<BR>&nbsp;&nbsp;&nbsp; self.change (row+1,=20
column+1)<BR>&nbsp;<BR>&nbsp;def change (self, row, column):<BR><FONT=20
color=3D#000000 face=3DArial size=3D4><STRONG>&nbsp; ##if self.butt =
[row] [column]=20
[&quot;background&quot; =3D=3D &quot;white&quot;]: *2 <BR>&nbsp; ## =
self.butt [row]=20
[column] [&quot;background&quot;] =3D &quot;black&quot;<BR>&nbsp;=20
##else:<BR>&nbsp; ## self.butt [row] [column] [&quot;background&quot;] =
=3D=20
&quot;white&quot;<BR></STRONG></FONT>&nbsp; print row, column ##only=20
example<BR>def main ():<BR>&nbsp;app =3D XXX=20
(Tkinter.Tk())<BR>&nbsp;app.pack()<BR>&nbsp;app.mainloop()<BR>if =
__name__ =3D=3D=20
'__main__':<BR>&nbsp;main()</FONT></DIV></BODY></HTML>

------=_NextPart_000_0004_01BFC509.2FDC2F80--