[Tutor] 15 puzzle

Maritza Rodriguez maritza_rodz@hotmail.com
Tue, 08 May 2001 11:49:03 -0500


I've been working with Glen Barnett on my program for the 15 puzzle.  He 
came up with this program which gives us the 4x4 matrix with the numbers 
1-15 in order from left to right and a blank space after the 15.  Also, it 
gives two additional buttons under the matrix, one that reads "SCRAMBLE" and 
another that reads "DONE".  We have not been able to figure out how to move 
the buttons so that if a button is clicked on (one that is next to the blank 
space, of course), it will automatically just pop into the blank spot.  Does 
anyone have any suggestions?

Maritza

from Tkinter import *
import sys

root = Tk()
root.title("15 PUZZLE")

frame = Frame(root)
frame["height"]=100
frame["width"]=100
frame["borderwidth"]=4
frame["relief"]=RAISED
frame.grid(row=0,column=0,sticky=E+W+N+S)

frame2 = Frame(root)
frame2["height"]=10
frame2["width"]=80
frame2["borderwidth"]=4
frame2["relief"]=RAISED
frame2.grid(row=1,column=0,sticky=E+W+N+S)



names=["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15"]

n=0
for i in range (4):
    for j in range(4):
        if n!=15:
         item=Button(frame,text=names[n])
         item.grid(row=i,column=j,sticky=E+W+N+S)
         n=n+1

quit = Button(root,text="DONE")
quit.grid(row=2,column=0,sticky=E+W+N+S)
scramble = Button(root,text="SCRAMBLE")
scramble.grid(row=3,column=0,sticky=E+W+N+S)


root.mainloop()

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com