I'm trying to make the old box game (if you are unfamiliar with it you can play it here: http://www.tcastle.com/games/dots/dots.html I've seen it go by many different names though) and I was wondering if there was a way to get the pictures on buttons to change easily
this is the code I have so far:
from Tkinter import *
lr = {}
ud = {}
for x in range(1,21):
lr["%d"%x] = ""
ud["%d"%x] = ""
class App:
def __init__(self, master):
frame = Frame(master)
frame.grid()
global xy,xy1,canvas
xy,xy1 = IntVar(0),""
row,column = 10,1
canvas = Canvas(frame)
canvas.grid()
for x in range(1,26):
Radiobutton(canvas, variable=xy, value=x,command=self.move).grid(row=row,column=column)
column = column + 2
if column == 11:
row,column = row-2,1
row,column = 10,2
for x in range(1,21):
Button(canvas, relief=FLAT, text=x,width=1,height=1, state=DISABLED).grid(row=row,column=column)
column = column + 2
if column == 10:
row,column = row-2,2
row,column = 9,1
for x in range(1,21):
Button(canvas, relief=FLAT, text=x,width=1,height=1, state=DISABLED).grid(row=row,column=column)
column = column + 2
if column == 11:
row,column = row-2,1
row,column = 9,2
for x in range(1,17):
Button(canvas, relief=FLAT, width=1,height=1, state=DISABLED).grid(row=row,column=column)
column = column + 2
if column == 10:
row,column = row-2,2
def move(self):
global xy,xy1,xy2
if xy1 == "":
xy1 = xy.get()
else:
xy2 = xy.get()
if abs(xy1-xy2) == 1 or abs(xy1-xy2) == 5:
x1 = xy1
y1 = ((xy1-1)/5)+1
while x1 > 5:
x1 = x1 - 5
x2 = xy2
y2 = ((xy2-1)/5)+1
while x2 > 5:
x2 = x2 - 5
print x1,y1,"\n",x2,y2
xy.set(0)
xy1 = ""
root = Tk()
d = App(root)
root.wait_window()