[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> </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
"command" 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>) =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> </DIV>
<DIV><FONT color=3D#000000 face=3DArial size=3D2>class XXX=20
(Tkinter.Frame):<BR> <BR> rows =3D 8<BR> columns =3D=20
8<BR> <BR> def __init__(self, root): <BR> =
Tkinter.Frame.__init__=20
(self, root)<BR> self.butt =3D []<BR> self.butt =3D=20
[self.butt]*self.rows<BR> for row in range =
(self.rows):<BR> =20
self.butt [row] =3D [self.butt] * self.columns<BR> for =
column in range=20
(self.columns):<BR> =
=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> self.butt=20
[row][column].grid(row=3Drow, column=3Dcolumn)<BR> =
<BR> <BR> def=20
surrounding (self, row, column): ## I know this is not =
a good=20
algorithem<BR> <BR> if row =3D=3D 0:<BR> if =
column =3D=3D=20
0:<BR> self.change (0, 1)<BR> =
self.change=20
(1, 0)<BR> self.change (1, 1)<BR> elif =
column =3D=3D=20
self.columns:<BR> self.change (0, =
2)<BR> =20
self.change (1, 2)<BR> self.change (1, =
3)<BR> =20
else:<BR> self.change (0, =
column-1)<BR> =20
self.change (0, column+1)<BR> self.change (1,=20
column-1)<BR> self.change (1, =
column)<BR> =20
self.change (1, column+1)<BR> elif row =3D=3D =
self.rows:<BR> if=20
column =3D=3D 0:<BR> self.change (row-1, =
0)<BR> =20
self.change (row-1, 1)<BR> self.change (row,=20
1)<BR> elif column =3D=3D =
self.columns:<BR> =20
self.change (row, column-1)<BR> self.change (row-1,=20
column-1)<BR> self.change (row-1, =
column)<BR> =20
else:<BR> self.change (row, =
column-1)<BR> =20
self.change (row-1, column-1)<BR> self.change (row-1,=20
column)<BR> self.change (row-1,=20
column+1)<BR> self.change (row, column+1)<BR> =20
else:<BR> if column =3D=3D 0:<BR> =
self.change (row-1,=20
column)<BR> self.change (row-1,=20
column+1)<BR> self.change (row,=20
column+1)<BR> self.change (row+1,=20
column+1)<BR> self.change (row+1, =
column)<BR> elif=20
column =3D=3D self.columns:<BR> self.change (row+1,=20
column)<BR> self.change (row+1,=20
column-1)<BR> self.change (row,=20
column-1)<BR> self.change (row-1,=20
column-1)<BR> self.change (row-1, =
column)<BR> =20
else:<BR> self.change (row+1, =
column)<BR> =20
self.change (row+1, column-1)<BR> self.change (row,=20
column-1)<BR> self.change (row-1,=20
column-1)<BR> self.change (row-1,=20
column)<BR> self.change (row-1,=20
column+1)<BR> self.change (row,=20
column+1)<BR> self.change (row+1,=20
column+1)<BR> <BR> def change (self, row, column):<BR><FONT=20
color=3D#000000 face=3DArial size=3D4><STRONG> ##if self.butt =
[row] [column]=20
["background" =3D=3D "white"]: *2 <BR> ## =
self.butt [row]=20
[column] ["background"] =3D "black"<BR> =20
##else:<BR> ## self.butt [row] [column] ["background"] =
=3D=20
"white"<BR></STRONG></FONT> print row, column ##only=20
example<BR>def main ():<BR> app =3D XXX=20
(Tkinter.Tk())<BR> app.pack()<BR> app.mainloop()<BR>if =
__name__ =3D=3D=20
'__main__':<BR> main()</FONT></DIV></BODY></HTML>
------=_NextPart_000_0004_01BFC509.2FDC2F80--