hi,
I recently created a fully working version of Minesweeper using Tkinter and I'll try to help you because it was rather hard to figure out the logic :) Here's my idea for all the buttons for the game:
Note: I am assuming that you know about dictionaries :) if not it gets more complicated :)
have a dictionary with the button instances as keys and a value that represents the button number 0 - 80 in your case. Here's what I mean:
from Tkinter import *
root = Tk(); root.geometry( "225x300+530+180" )
buttons = {}
def makeChoice( event ):
global buttons
print buttons[ event.widget ]
def createBoard():
global buttons
buttonNum = 0
x = -225
y = 65
for b in range( 9 ):
for b2 in range( 9 ):
button = Button( root, text = " ", font = "Courier 9", width = 2, bd = 3 ); button.place( relx = 1, x = x, y = y )
buttons[ button ] = buttonNum
buttonNum += 1
button.bind( "<Button-1>", makeChoice )
x += 25
x = -225
y += 26
createBoard()
mainloop()
when you press a button, it calls the makeChoice function which then selects the value of the widget from the dictionary.
hope this gives you some ideas :) note that this is my approach, there are probably easier ways :)
masterofpuppets
Posting Whiz in Training
272 posts since Jul 2009
Reputation Points: 20
Solved Threads: 74