Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Acting like button are being pressed (BUT THEY ARE NOT) Please Help

Reply
Thread Tools

Acting like button are being pressed (BUT THEY ARE NOT) Please Help

 
 
mcsejung
Guest
Posts: n/a
 
      02-22-2008
"""
-----------------------------------------------------------------------------
Name: _tkUnderWaterDemolitionRemoval.py
Purpose: The classic Under Water Demolition Removal game

Author: mcsejung

Created: 2008/02/15
RCS-ID: $Id: _tkUnderWaterDemolitionRemoval.py $
Copyright: (c) 2008
Licence: GPL
This program is free software; you can redistribute it and/or
modify
it under the terms of the GNU General Public License as published
by
the Free Software Foundation; either version 2 of the License
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA

Maintenance: 2008/02/15 The classic Under Water Demolition Removal
game
-----------------------------------------------------------------------------
"""
from Tkinter import *

class App:
global matrix
def __init__(self, master):
#Define the matrix
self.var2entry = range(
for i in range(:
self.var2entry[i] = range(

#Define the outer frame
frame = Frame(master)
frame.grid()

#Define a square
self.var2entry[0][0] = StringVar()
self.entry00 = Button(frame, textvariable=self.var2entry[0]
[0], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry00.bind('<Button-1>', self.leftClick(self.entry00,
0, 0)) # bind left mouse click
self.entry00.bind('<Button-3>', self.rightClick(self.entry00,
0, 0)) # bind right mouse click
self.entry00.grid(row=0, column=0, sticky=W,)

#Define a square
self.var2entry[0][1] = StringVar()
self.entry01 = Button(frame, textvariable=self.var2entry[0]
[1], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry01.bind('<Button-1>', self.leftClick(self.entry01,
0, 1)) # bind left mouse click
self.entry01.bind('<Button-3>', self.rightClick(self.entry01,
0, 1)) # bind right mouse click
self.entry01.grid(row=0, column=1, sticky=W,)

#Define a square
self.var2entry[0][2] = StringVar()
self.entry02 = Button(frame, textvariable=self.var2entry[0]
[2], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry02.bind('<Button-1>', self.leftClick(self.entry02,
0, 2)) # bind left mouse click
self.entry02.bind('<Button-3>', self.rightClick(self.entry02,
0, 2)) # bind right mouse click
self.entry02.grid(row=0, column=2, sticky=W,)

#Define a square
self.var2entry[0][3] = StringVar()
self.entry03 = Button(frame, textvariable=self.var2entry[0]
[3], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry03.bind('<Button-1>', self.leftClick(self.entry03,
0, 3)) # bind left mouse click
self.entry03.bind('<Button-3>', self.rightClick(self.entry03,
0, 3)) # bind right mouse click
self.entry03.grid(row=0, column=3, sticky=W,)

#Define a square
self.var2entry[0][4] = StringVar()
self.entry04 = Button(frame, textvariable=self.var2entry[0]
[4], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry04.bind('<Button-1>', self.leftClick(self.entry04,
0, 4)) # bind left mouse click
self.entry04.bind('<Button-3>', self.rightClick(self.entry04,
0, 4)) # bind right mouse click
self.entry04.grid(row=0, column=4, sticky=W,)

#Define a square
self.var2entry[0][5] = StringVar()
self.entry05 = Button(frame, textvariable=self.var2entry[0]
[5], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry05.bind('<Button-1>', self.leftClick(self.entry05,
0, 5)) # bind left mouse click
self.entry05.bind('<Button-3>', self.rightClick(self.entry05,
0, 5)) # bind right mouse click
self.entry05.grid(row=0, column=5, sticky=W,)

#Define a square
self.var2entry[0][6] = StringVar()
self.entry06 = Button(frame, textvariable=self.var2entry[0]
[6], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry06.bind('<Button-1>', self.leftClick(self.entry06,
0, 6)) # bind left mouse click
self.entry06.bind('<Button-3>', self.rightClick(self.entry06,
0, 6)) # bind right mouse click
self.entry06.grid(row=0, column=6, sticky=W,)

#Define a square
self.var2entry[0][7] = StringVar()
self.entry07 = Button(frame, textvariable=self.var2entry[0]
[7], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry07.bind('<Button-1>', self.leftClick(self.entry07,
0, 7)) # bind left mouse click
self.entry07.bind('<Button-3>', self.rightClick(self.entry07,
0, 7)) # bind right mouse click
self.entry07.grid(row=0, column=7, sticky=W,)



#Define a square
self.var2entry[1][0] = StringVar()
self.entry10 = Button(frame, textvariable=self.var2entry[1]
[0], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry10.bind('<Button-1>', self.leftClick(self.entry10,
1, 0)) # bind left mouse click
self.entry10.bind('<Button-3>', self.rightClick(self.entry10,
1, 0)) # bind right mouse click
self.entry10.grid(row=1, column=0, sticky=W,)

#Define a square
self.var2entry[1][1] = StringVar()
self.entry11 = Button(frame, textvariable=self.var2entry[1]
[1], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry11.bind('<Button-1>', self.leftClick(self.entry11,
1, 1)) # bind left mouse click
self.entry11.bind('<Button-3>', self.rightClick(self.entry11,
1, 1)) # bind right mouse click
self.entry11.grid(row=1, column=1, sticky=W,)

#Define a square
self.var2entry[1][2] = StringVar()
self.entry12 = Button(frame, textvariable=self.var2entry[1]
[2], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry12.bind('<Button-1>', self.leftClick(self.entry12,
1, 2)) # bind left mouse click
self.entry12.bind('<Button-3>', self.rightClick(self.entry12,
1, 2)) # bind right mouse click
self.entry12.grid(row=1, column=2, sticky=W,)

#Define a square
self.var2entry[1][3] = StringVar()
self.entry13 = Button(frame, textvariable=self.var2entry[1]
[3], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry13.bind('<Button-1>', self.leftClick(self.entry13,
1, 3)) # bind left mouse click
self.entry13.bind('<Button-3>', self.rightClick(self.entry13,
1, 3)) # bind right mouse click
self.entry13.grid(row=1, column=3, sticky=W,)

#Define a square
self.var2entry[1][4] = StringVar()
self.entry14 = Button(frame, textvariable=self.var2entry[1]
[4], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry14.bind('<Button-1>', self.leftClick(self.entry14,
1, 4)) # bind left mouse click
self.entry14.bind('<Button-3>', self.rightClick(self.entry14,
1, 4)) # bind right mouse click
self.entry14.grid(row=1, column=4, sticky=W,)

#Define a square
self.var2entry[1][5] = StringVar()
self.entry15 = Button(frame, textvariable=self.var2entry[1]
[5], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry15.bind('<Button-1>', self.leftClick(self.entry15,
1, 5)) # bind left mouse click
self.entry15.bind('<Button-3>', self.rightClick(self.entry15,
1, 5)) # bind right mouse click
self.entry15.grid(row=1, column=5, sticky=W,)

#Define a square
self.var2entry[1][6] = StringVar()
self.entry16 = Button(frame, textvariable=self.var2entry[1]
[6], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry16.bind('<Button-1>', self.leftClick(self.entry16,
1, 6)) # bind left mouse click
self.entry16.bind('<Button-3>', self.rightClick(self.entry16,
1, 6)) # bind right mouse click
self.entry16.grid(row=1, column=6, sticky=W,)

#Define a square
self.var2entry[1][7] = StringVar()
self.entry17 = Button(frame, textvariable=self.var2entry[1]
[7], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry17.bind('<Button-1>', self.leftClick(self.entry17,
1, 7)) # bind left mouse click
self.entry17.bind('<Button-3>', self.rightClick(self.entry17,
1, 7)) # bind right mouse click
self.entry17.grid(row=1, column=7, sticky=W,)



#Define a square
self.var2entry[2][0] = StringVar()
self.entry20 = Button(frame, textvariable=self.var2entry[2]
[0], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry20.bind('<Button-1>', self.leftClick(self.entry20,
2, 0)) # bind left mouse click
self.entry20.bind('<Button-3>', self.rightClick(self.entry20,
2, 0)) # bind right mouse click
self.entry20.grid(row=2, column=0, sticky=W,)

#Define a square
self.var2entry[2][1] = StringVar()
self.entry21 = Button(frame, textvariable=self.var2entry[2]
[1], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry21.bind('<Button-1>', self.leftClick(self.entry21,
2, 1)) # bind left mouse click
self.entry21.bind('<Button-3>', self.rightClick(self.entry21,
2, 1)) # bind right mouse click
self.entry21.grid(row=2, column=1, sticky=W,)

#Define a square
self.var2entry[2][2] = StringVar()
self.entry22 = Button(frame, textvariable=self.var2entry[2]
[2], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry22.bind('<Button-1>', self.leftClick(self.entry22,
2, 2)) # bind left mouse click
self.entry22.bind('<Button-3>', self.rightClick(self.entry22,
2, 2)) # bind right mouse click
self.entry22.grid(row=2, column=2, sticky=W,)

#Define a square
self.var2entry[2][3] = StringVar()
self.entry23 = Button(frame, textvariable=self.var2entry[2]
[3], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry23.bind('<Button-1>', self.leftClick(self.entry23,
2, 3)) # bind left mouse click
self.entry23.bind('<Button-3>', self.rightClick(self.entry23,
2, 3)) # bind right mouse click
self.entry23.grid(row=2, column=3, sticky=W,)

#Define a square
self.var2entry[2][4] = StringVar()
self.entry24 = Button(frame, textvariable=self.var2entry[2]
[4], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry24.bind('<Button-1>', self.leftClick(self.entry24,
2, 4)) # bind left mouse click
self.entry24.bind('<Button-3>', self.rightClick(self.entry24,
2, 4)) # bind right mouse click
self.entry24.grid(row=2, column=4, sticky=W,)

#Define a square
self.var2entry[2][5] = StringVar()
self.entry25 = Button(frame, textvariable=self.var2entry[2]
[5], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry25.bind('<Button-1>', self.leftClick(self.entry25,
2, 5)) # bind left mouse click
self.entry25.bind('<Button-3>', self.rightClick(self.entry25,
2, 5)) # bind right mouse click
self.entry25.grid(row=2, column=5, sticky=W,)

#Define a square
self.var2entry[2][6] = StringVar()
self.entry26 = Button(frame, textvariable=self.var2entry[2]
[6], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry26.bind('<Button-1>', self.leftClick(self.entry26,
2, 6)) # bind left mouse click
self.entry26.bind('<Button-3>', self.rightClick(self.entry26,
2, 6)) # bind right mouse click
self.entry26.grid(row=2, column=6, sticky=W,)

#Define a square
self.var2entry[2][7] = StringVar()
self.entry27 = Button(frame, textvariable=self.var2entry[2]
[7], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry27.bind('<Button-1>', self.leftClick(self.entry27,
2, 7)) # bind left mouse click
self.entry27.bind('<Button-3>', self.rightClick(self.entry27,
2, 7)) # bind right mouse click
self.entry27.grid(row=2, column=7, sticky=W,)



#Define a square
self.var2entry[3][0] = StringVar()
self.entry30 = Button(frame, textvariable=self.var2entry[3]
[0], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry30.bind('<Button-1>', self.leftClick(self.entry30,
3, 0)) # bind left mouse click
self.entry30.bind('<Button-3>', self.rightClick(self.entry30,
3, 0)) # bind right mouse click
self.entry30.grid(row=3, column=0, sticky=W,)

#Define a square
self.var2entry[3][1] = StringVar()
self.entry31 = Button(frame, textvariable=self.var2entry[3]
[1], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry31.bind('<Button-1>', self.leftClick(self.entry31,
3, 1)) # bind left mouse click
self.entry31.bind('<Button-3>', self.rightClick(self.entry31,
3, 1)) # bind right mouse click
self.entry31.grid(row=3, column=1, sticky=W,)

#Define a square
self.var2entry[3][2] = StringVar()
self.entry32 = Button(frame, textvariable=self.var2entry[3]
[2], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry32.bind('<Button-1>', self.leftClick(self.entry32,
3, 2)) # bind left mouse click
self.entry32.bind('<Button-3>', self.rightClick(self.entry32,
3, 2)) # bind right mouse click
self.entry32.grid(row=3, column=2, sticky=W,)

#Define a square
self.var2entry[3][3] = StringVar()
self.entry33 = Button(frame, textvariable=self.var2entry[3]
[3], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry33.bind('<Button-1>', self.leftClick(self.entry33,
3, 3)) # bind left mouse click
self.entry33.bind('<Button-3>', self.rightClick(self.entry33,
3, 3)) # bind right mouse click
self.entry33.grid(row=3, column=3, sticky=W,)

#Define a square
self.var2entry[3][4] = StringVar()
self.entry34 = Button(frame, textvariable=self.var2entry[3]
[4], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry34.bind('<Button-1>', self.leftClick(self.entry34,
3, 4)) # bind left mouse click
self.entry34.bind('<Button-3>', self.rightClick(self.entry34,
3, 4)) # bind right mouse click
self.entry34.grid(row=3, column=4, sticky=W,)

#Define a square
self.var2entry[3][5] = StringVar()
self.entry35 = Button(frame, textvariable=self.var2entry[3]
[5], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry35.bind('<Button-1>', self.leftClick(self.entry35,
3, 5)) # bind left mouse click
self.entry35.bind('<Button-3>', self.rightClick(self.entry35,
3, 5)) # bind right mouse click
self.entry35.grid(row=3, column=5, sticky=W,)

#Define a square
self.var2entry[3][6] = StringVar()
self.entry36 = Button(frame, textvariable=self.var2entry[3]
[6], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry36.bind('<Button-1>', self.leftClick(self.entry36,
3, 6)) # bind left mouse click
self.entry36.bind('<Button-3>', self.rightClick(self.entry36,
3, 6)) # bind right mouse click
self.entry36.grid(row=3, column=6, sticky=W,)

#Define a square
self.var2entry[3][7] = StringVar()
self.entry37 = Button(frame, textvariable=self.var2entry[3]
[7], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry37.bind('<Button-1>', self.leftClick(self.entry37,
3, 7)) # bind left mouse click
self.entry37.bind('<Button-3>', self.rightClick(self.entry37,
3, 7)) # bind right mouse click
self.entry37.grid(row=3, column=7, sticky=W,)



#Define a square
self.var2entry[4][0] = StringVar()
self.entry40 = Button(frame, textvariable=self.var2entry[4]
[0], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry40.bind('<Button-1>', self.leftClick(self.entry40,
4, 0)) # bind left mouse click
self.entry40.bind('<Button-3>', self.rightClick(self.entry40,
4, 0)) # bind right mouse click
self.entry40.grid(row=4, column=0, sticky=W,)

#Define a square
self.var2entry[4][1] = StringVar()
self.entry41 = Button(frame, textvariable=self.var2entry[4]
[1], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry41.bind('<Button-1>', self.leftClick(self.entry41,
4, 1)) # bind left mouse click
self.entry41.bind('<Button-3>', self.rightClick(self.entry41,
4, 1)) # bind right mouse click
self.entry41.grid(row=4, column=1, sticky=W,)

#Define a square
self.var2entry[4][2] = StringVar()
self.entry42 = Button(frame, textvariable=self.var2entry[4]
[2], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry42.bind('<Button-1>', self.leftClick(self.entry42,
4, 2)) # bind left mouse click
self.entry42.bind('<Button-3>', self.rightClick(self.entry42,
4, 2)) # bind right mouse click
self.entry42.grid(row=4, column=2, sticky=W,)

#Define a square
self.var2entry[4][3] = StringVar()
self.entry43 = Button(frame, textvariable=self.var2entry[4]
[3], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry43.bind('<Button-1>', self.leftClick(self.entry43,
4, 3)) # bind left mouse click
self.entry43.bind('<Button-3>', self.rightClick(self.entry43,
4, 3)) # bind right mouse click
self.entry43.grid(row=4, column=3, sticky=W,)

#Define a square
self.var2entry[4][4] = StringVar()
self.entry44 = Button(frame, textvariable=self.var2entry[4]
[4], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry44.bind('<Button-1>', self.leftClick(self.entry44,
4, 4)) # bind left mouse click
self.entry44.bind('<Button-3>', self.rightClick(self.entry44,
4, 4)) # bind right mouse click
self.entry44.grid(row=4, column=4, sticky=W,)

#Define a square
self.var2entry[4][5] = StringVar()
self.entry45 = Button(frame, textvariable=self.var2entry[4]
[5], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry45.bind('<Button-1>', self.leftClick(self.entry45,
4, 5)) # bind left mouse click
self.entry45.bind('<Button-3>', self.rightClick(self.entry45,
4, 5)) # bind right mouse click
self.entry45.grid(row=4, column=5, sticky=W,)

#Define a square
self.var2entry[4][6] = StringVar()
self.entry46 = Button(frame, textvariable=self.var2entry[4]
[6], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry46.bind('<Button-1>', self.leftClick(self.entry46,
4, 6)) # bind left mouse click
self.entry46.bind('<Button-3>', self.rightClick(self.entry46,
4, 6)) # bind right mouse click
self.entry46.grid(row=4, column=6, sticky=W,)

#Define a square
self.var2entry[4][7] = StringVar()
self.entry47 = Button(frame, textvariable=self.var2entry[4]
[7], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry47.bind('<Button-1>', self.leftClick(self.entry47,
4, 7)) # bind left mouse click
self.entry47.bind('<Button-3>', self.rightClick(self.entry47,
4, 7)) # bind right mouse click
self.entry47.grid(row=4, column=7, sticky=W,)



#Define a square
self.var2entry[5][0] = StringVar()
self.entry50 = Button(frame, textvariable=self.var2entry[5]
[0], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry50.bind('<Button-1>', self.leftClick(self.entry50,
5, 0)) # bind left mouse click
self.entry50.bind('<Button-3>', self.rightClick(self.entry50,
5, 0)) # bind right mouse click
self.entry50.grid(row=5, column=0, sticky=W,)

#Define a square
self.var2entry[5][1] = StringVar()
self.entry51 = Button(frame, textvariable=self.var2entry[5]
[1], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry51.bind('<Button-1>', self.leftClick(self.entry51,
5, 1)) # bind left mouse click
self.entry51.bind('<Button-3>', self.rightClick(self.entry51,
5, 1)) # bind right mouse click
self.entry51.grid(row=5, column=1, sticky=W,)

#Define a square
self.var2entry[5][2] = StringVar()
self.entry52 = Button(frame, textvariable=self.var2entry[5]
[2], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry52.bind('<Button-1>', self.leftClick(self.entry52,
5, 2)) # bind left mouse click
self.entry52.bind('<Button-3>', self.rightClick(self.entry52,
5, 2)) # bind right mouse click
self.entry52.grid(row=5, column=2, sticky=W,)

#Define a square
self.var2entry[5][3] = StringVar()
self.entry53 = Button(frame, textvariable=self.var2entry[5]
[3], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry53.bind('<Button-1>', self.leftClick(self.entry53,
5, 3)) # bind left mouse click
self.entry53.bind('<Button-3>', self.rightClick(self.entry53,
5, 3)) # bind right mouse click
self.entry53.grid(row=5, column=3, sticky=W,)

#Define a square
self.var2entry[5][4] = StringVar()
self.entry54 = Button(frame, textvariable=self.var2entry[5]
[4], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry54.bind('<Button-1>', self.leftClick(self.entry54,
5, 4)) # bind left mouse click
self.entry54.bind('<Button-3>', self.rightClick(self.entry54,
5, 4)) # bind right mouse click
self.entry54.grid(row=5, column=4, sticky=W,)

#Define a square
self.var2entry[5][5] = StringVar()
self.entry55 = Button(frame, textvariable=self.var2entry[5]
[5], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry55.bind('<Button-1>', self.leftClick(self.entry55,
5, 5)) # bind left mouse click
self.entry55.bind('<Button-3>', self.rightClick(self.entry55,
5, 5)) # bind right mouse click
self.entry55.grid(row=5, column=5, sticky=W,)

#Define a square
self.var2entry[5][6] = StringVar()
self.entry56 = Button(frame, textvariable=self.var2entry[5]
[6], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry56.bind('<Button-1>', self.leftClick(self.entry56,
5, 6)) # bind left mouse click
self.entry56.bind('<Button-3>', self.rightClick(self.entry56,
5, 6)) # bind right mouse click
self.entry56.grid(row=5, column=6, sticky=W,)

#Define a square
self.var2entry[5][7] = StringVar()
self.entry57 = Button(frame, textvariable=self.var2entry[5]
[7], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry57.bind('<Button-1>', self.leftClick(self.entry57,
5, 7)) # bind left mouse click
self.entry57.bind('<Button-3>', self.rightClick(self.entry57,
5, 7)) # bind right mouse click
self.entry57.grid(row=5, column=7, sticky=W,)



#Define a square
self.var2entry[6][0] = StringVar()
self.entry60 = Button(frame, textvariable=self.var2entry[6]
[0], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry60.bind('<Button-1>', self.leftClick(self.entry60,
6, 0)) # bind left mouse click
self.entry60.bind('<Button-3>', self.rightClick(self.entry60,
6, 0)) # bind right mouse click
self.entry60.grid(row=6, column=0, sticky=W,)

#Define a square
self.var2entry[6][1] = StringVar()
self.entry61 = Button(frame, textvariable=self.var2entry[6]
[1], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry61.bind('<Button-1>', self.leftClick(self.entry61,
6, 1)) # bind left mouse click
self.entry61.bind('<Button-3>', self.rightClick(self.entry61,
6, 1)) # bind right mouse click
self.entry61.grid(row=6, column=1, sticky=W,)

#Define a square
self.var2entry[6][2] = StringVar()
self.entry62 = Button(frame, textvariable=self.var2entry[6]
[2], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry62.bind('<Button-1>', self.leftClick(self.entry62,
6, 2)) # bind left mouse click
self.entry62.bind('<Button-3>', self.rightClick(self.entry62,
6, 2)) # bind right mouse click
self.entry62.grid(row=6, column=2, sticky=W,)

#Define a square
self.var2entry[6][3] = StringVar()
self.entry63 = Button(frame, textvariable=self.var2entry[6]
[3], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry63.bind('<Button-1>', self.leftClick(self.entry63,
6, 3)) # bind left mouse click
self.entry63.bind('<Button-3>', self.rightClick(self.entry63,
6, 3)) # bind right mouse click
self.entry63.grid(row=6, column=3, sticky=W,)

#Define a square
self.var2entry[6][4] = StringVar()
self.entry64 = Button(frame, textvariable=self.var2entry[6]
[4], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry64.bind('<Button-1>', self.leftClick(self.entry64,
6, 4)) # bind left mouse click
self.entry64.bind('<Button-3>', self.rightClick(self.entry64,
6, 4)) # bind right mouse click
self.entry64.grid(row=6, column=4, sticky=W,)

#Define a square
self.var2entry[6][5] = StringVar()
self.entry65 = Button(frame, textvariable=self.var2entry[6]
[5], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry65.bind('<Button-1>', self.leftClick(self.entry65,
6, 5)) # bind left mouse click
self.entry65.bind('<Button-3>', self.rightClick(self.entry65,
6, 5)) # bind right mouse click
self.entry65.grid(row=6, column=5, sticky=W,)

#Define a square
self.var2entry[6][6] = StringVar()
self.entry66 = Button(frame, textvariable=self.var2entry[6]
[6], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry66.bind('<Button-1>', self.leftClick(self.entry66,
6, 6)) # bind left mouse click
self.entry66.bind('<Button-3>', self.rightClick(self.entry66,
6, 6)) # bind right mouse click
self.entry66.grid(row=6, column=6, sticky=W,)

#Define a square
self.var2entry[6][7] = StringVar()
self.entry67 = Button(frame, textvariable=self.var2entry[6]
[7], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry67.bind('<Button-1>', self.leftClick(self.entry67,
6, 7)) # bind left mouse click
self.entry67.bind('<Button-3>', self.rightClick(self.entry67,
6, 7)) # bind right mouse click
self.entry67.grid(row=6, column=7, sticky=W,)



#Define a square
self.var2entry[7][0] = StringVar()
self.entry70 = Button(frame, textvariable=self.var2entry[7]
[0], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry70.bind('<Button-1>', self.leftClick(self.entry70,
7, 0)) # bind left mouse click
self.entry70.bind('<Button-3>', self.rightClick(self.entry70,
7, 0)) # bind right mouse click
self.entry70.grid(row=7, column=0, sticky=W,)

#Define a square
self.var2entry[7][1] = StringVar()
self.entry71 = Button(frame, textvariable=self.var2entry[7]
[1], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry71.bind('<Button-1>', self.leftClick(self.entry71,
7, 1)) # bind left mouse click
self.entry71.bind('<Button-3>', self.rightClick(self.entry71,
7, 1)) # bind right mouse click
self.entry71.grid(row=7, column=1, sticky=W,)

#Define a square
self.var2entry[7][2] = StringVar()
self.entry72 = Button(frame, textvariable=self.var2entry[7]
[2], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry72.bind('<Button-1>', self.leftClick(self.entry72,
7, 2)) # bind left mouse click
self.entry72.bind('<Button-3>', self.rightClick(self.entry72,
7, 2)) # bind right mouse click
self.entry72.grid(row=7, column=2, sticky=W,)

#Define a square
self.var2entry[7][3] = StringVar()
self.entry73 = Button(frame, textvariable=self.var2entry[7]
[3], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry73.bind('<Button-1>', self.leftClick(self.entry73,
7, 3)) # bind left mouse click
self.entry73.bind('<Button-3>', self.rightClick(self.entry73,
7, 3)) # bind right mouse click
self.entry73.grid(row=7, column=3, sticky=W,)

#Define a square
self.var2entry[7][4] = StringVar()
self.entry74 = Button(frame, textvariable=self.var2entry[7]
[4], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry74.bind('<Button-1>', self.leftClick(self.entry74,
7, 4)) # bind left mouse click
self.entry74.bind('<Button-3>', self.rightClick(self.entry74,
7, 4)) # bind right mouse click
self.entry74.grid(row=7, column=4, sticky=W,)

#Define a square
self.var2entry[7][5] = StringVar()
self.entry75 = Button(frame, textvariable=self.var2entry[7]
[5], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry75.bind('<Button-1>', self.leftClick(self.entry75,
7, 5)) # bind left mouse click
self.entry75.bind('<Button-3>', self.rightClick(self.entry75,
7, 5)) # bind right mouse click
self.entry75.grid(row=7, column=5, sticky=W,)

#Define a square
self.var2entry[7][6] = StringVar()
self.entry76 = Button(frame, textvariable=self.var2entry[7]
[6], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry76.bind('<Button-1>', self.leftClick(self.entry76,
7, 6)) # bind left mouse click
self.entry76.bind('<Button-3>', self.rightClick(self.entry76,
7, 6)) # bind right mouse click
self.entry76.grid(row=7, column=6, sticky=W,)

#Define a square
self.var2entry[7][7] = StringVar()
self.entry77 = Button(frame, textvariable=self.var2entry[7]
[7], fg="blue", bg="grey", font=("Verdana", 12), relief=RAISED,
width=2, borderwidth=3)
self.entry77.bind('<Button-1>', self.leftClick(self.entry77,
7, 7)) # bind left mouse click
self.entry77.bind('<Button-3>', self.rightClick(self.entry77,
7, 7)) # bind right mouse click
self.entry77.grid(row=7, column=7, sticky=W,)


#Define a BOOM!!!
self.var2entry80 = StringVar()
self.var2entry80.set(' ')
self.entry80 = Button(frame, textvariable=self.var2entry80,
fg="red", bg="blue", font=("Verdana", 12), relief=FLAT, width=25,
borderwidth=3)
self.entry80.grid(row=8, column=0, sticky=W, columnspan=


#Define a Quit
self.var2entry90 = StringVar()
self.var2entry90.set('QUIT')
self.entry90 = Button(frame, command=self.quit,
textvariable=self.var2entry90, fg="red", bg="blue", font=("Verdana",
12), relief=RAISED, width=25, borderwidth=3)
self.entry90.grid(row=9, column=0, sticky=W, columnspan=


def quit(self):
#Chop down the tree and pull out the roots
root.destroy()


def boom(self):
#Define a BOOM!!!
global time2quit
self.var2entry80.set('ssss BOOM!!!')
time2quit = 1


def you_WIN(self):
#Define a WIN!!!
global time2quit, youWIN, youAreTheWinner
youWIN += 1
if youWIN == youAreTheWinner:
self.var2entry80.set('**** YOU WIN!!! ****')
time2quit = 1


def leftClick(self, btn, R, C):
#Do something when the LEFT button is clicked
global time2quit, var2entry, matrix
if time2quit == 1:
self.quit()
if matrix[R][C] == 'x':
btn.config(fg='black')
self.var2entry[R][C].set(' ')
self.boom()
self.var2entry[R][C].set(matrix[R][C])
self.you_WIN()


def rightClick(self, btn, R, C):
#Do something when the RIGHT button is clicked
global var2entry
btn.config(fg='red')
self.var2entry[R][C].set(' ')


def genSolution():
import random
global matrix, time2quit, youWIN, youAreTheWinner
time2quit = youWIN = youAreTheWinner = 0

nudr = [random.randint(1, 64),random.randint(1,
64),random.randint(1, 64),random.randint(1, 64),random.randint(1,
64),random.randint(1, 64),random.randint(1, 64),random.randint(1, 64)]
matrix = range(
for i in range(:
matrix[i] = range(
for j in range(:
matrix[i][j] = random.randint(1, 64)
if matrix[i][j] in nudr:
matrix[i][j] = 'x'
youAreTheWinner += 1
else:
matrix[i][j] = int(0)

youAreTheWinner = 64 - youAreTheWinner

for i in range(:
for j in range(:
try:
if (i-1 < 0) or (j-1 < 0): pass
else:
if matrix[i-1][j-1] == 'x': matrix[i][j] += 1
except:
pass

try:
if (i-1 < 0): pass
else:
if matrix[i-1][j] == 'x': matrix[i][j] += 1
except:
pass

try:
if (i-1 < 0) or (j+1 > 7): pass
else:
if matrix[i-1][j+1] == 'x': matrix[i][j] += 1
except:
pass

try:
if (j-1 < 0): pass
else:
if matrix[i][j-1] == 'x': matrix[i][j] += 1
except:
pass

try:
if matrix[i][j] == 'x': pass
except:
pass

try:
if (j+1 > 7): pass
else:
if matrix[i][j+1] == 'x': matrix[i][j] += 1
except:
pass

try:
if (i+1 > 7) or (j-1 < 0): pass
else:
if matrix[i+1][j-1] == 'x': matrix[i][j] += 1
except:
pass

try:
if (i+1 > 7): pass
else:
if matrix[i+1][j] == 'x': matrix[i][j] += 1
except:
pass

try:
if (i+1 > 7) or (j+1 > 7): pass
else:
if matrix[i+1][j+1] == 'x': matrix[i][j] += 1
except:
pass

#Begin processing; request information
root = Tk()
root.tk_bisque()
root.title('Under Water Mine Field')

genSolution()

for i in range(:
print
for j in range(:
print matrix[i][j],
print

app = App(root)

root.mainloop()
 
Reply With Quote
 
 
 
 
Martin Franklin
Guest
Posts: n/a
 
      02-22-2008

> self.entry00.bind('<Button-1>', self.leftClick(self.entry00,
> 0, 0)) # bind left mouse click


Difficult to say for sure due to excessive code wrapping..
but I would say that these bind methods are calling the left and right
Click methods... rather than bind'ing them to the entry widgets.

there are a few good ways around this, lambda, class with __call__ etc
etc most of these can be found with a little googling (in case this is
homework)


Cheers,
Martin.



--
signature file not found, must be something I ate
 
Reply With Quote
 
 
 
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      02-22-2008
On Fri, 22 Feb 2008 06:48:37 -0800, mcsejung wrote:

> [snipped massive bit of code]


Sorry but dumping about 900 lines of code at people with no real question
in the message body and just sort of a question in the subject won't help
much to get answers.

Just a quick look at the code tells that it could use some loops to
refactor it into a **much** shorter piece of code.

Then get rid of the asterisk import, ``except``\s without a specific
exception to handle, and the``global`` statement before you repost the
problem.

Ciao,
Marc 'BlackJack' Rintsch
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 button form + which button was pressed Bill_W_Stephens@yahoo.com Javascript 1 04-04-2006 04:25 AM
Image button acting like submit button. Russell ASP .Net 3 06-24-2004 01:55 AM
Leave button depressed after being pressed Novice ASP .Net Web Controls 2 06-23-2004 02:55 AM
How to detect that a key is being pressed, not HAS been pressed earlier!?? Rune Python 6 01-29-2004 12:39 PM
If value in name field in top row disable submit button until add button is pressed or field is cleared. Chuck Javascript 0 11-10-2003 02:23 AM



Advertisments