Python连接四个游戏

Python连接四个游戏,python,tkinter,connect,Python,Tkinter,Connect,我目前正在制作一个Python版本的游戏Connect Four。这将是非常基本的,使用Tkinter作为接口。我想我已经准备好了大部分的代码,我没有收到任何错误,但它目前没有创建实际的游戏板。现在我只把它编码成7的第一行(游戏板是7x6),但它没有显示出来。代码如下: from Tkinter import * class cell: def __init__(self,cellNum,frame,game): self.Empty=PhotoImage(file='

我目前正在制作一个Python版本的游戏Connect Four。这将是非常基本的,使用Tkinter作为接口。我想我已经准备好了大部分的代码,我没有收到任何错误,但它目前没有创建实际的游戏板。现在我只把它编码成7的第一行(游戏板是7x6),但它没有显示出来。代码如下:

from Tkinter import *

class cell:
    def __init__(self,cellNum,frame,game):
        self.Empty=PhotoImage(file='empty.gif')
        self.Black=PhotoImage(file='black.gif')
        self.Red=PhotoImage(file='red.gif')
        self.b = Button(frame,image=self.Empty,command=self.makeMove)
        self.frame = frame
        self.game = game
        self.num = cellNum

    def pack(self):
        self.gameSquare.pack()

    def makeMove(self):
        Player = self.game.Player
        if self.Player == 'Black':
            self.b.config(image=self.Black)
            num = self.num
            self.game.moves[Player].append(num)
            self.game.free.remove(num)
            self.Player = 'Red'
        else:
            self.b.config(image=self.Red)
            self.Player = 'Black'
        self.turninfo.config(text=Player+"'s Turn")

    def restart(self):
        self.b.config(image=self.Empty)

class game:
    def __init__(self):
        self.win = Tk()
        self.win.title('Connect Four')
        self.win.config(bg="blue")
        self.cells=[]
        self.free = range(42)
        self.moves = { 'X' : [ ], 'O' : [ ] }
        self.Row1 = Frame(self.win)
        for i in range(7):
            self.cells.append(cell(i,self.Row1,self))
        self.Player = 'Black'

        self.titleFrame = Frame(self.win)
        self.title = Label(self.win,text="Connect Four",font=(200),fg='white', bg='blue')


        self.middleRow = Frame(self.win)
        self.turninfo = Label(self.middleRow,text=self.Player+"'s Turn", font=(200),fg='white',bg='blue')

        self.bottomRow = Frame(self.win)
        self.quitbutton = Button(self.bottomRow, text="Quit", command=self.win.destroy, font=(200))
        self.playbutton = Button(self.bottomRow, text="Play Again", command=self.restart, font=(200))

        self.titleFrame.pack()
        self.title.pack()
        self.Row1.pack()
        self.turninfo.pack()
        self.middleRow.pack()
        self.bottomRow.pack()
        self.quitbutton.pack(side="left")
        self.playbutton.pack(side="right")
        self.win.mainloop()

    def restart(self):
        self.Player = 'Black'
        self.turninfo.config(text=self.Player+"'s Turn")
        self.free = range(42)
        self.moves = {'Black' : [ ], 'Red' : [ ]}
        for c in self.cells:
            c.restart()

game = game()

有人看到导致游戏板按钮不显示的任何明显错误吗?还是一般的错误?谢谢。

别忘了把按钮装进框架里:

    self.b = Button(frame,image=self.Empty,command=self.makeMove)
    self.b.pack(side=LEFT)