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()

You have to retrieve and store the RadioButton object. This code stores the grid() object:

#
Radiobutton(canvas, variable=xy, value=x,command=self.move).grid(row=row,column=column)
#
# instead use
#
self.rb =Radiobutton(canvas, variable=xy, value=x,command=self.move, image=xxx.)
self.rb.grid(row=row,column=column)  # using "row" and "column" as names is confusing
#
# and then
self.rb.configure(image=yyy)

For configure options see http://www.astro.princeton.edu/~rhl/Tcl-Tk_docs/tk/button.n.html

ok thanks woooee that's kind of what I was looking for. I guess it will do for now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.