在 python 中塑造井字游戏

Shaping a tic tac toe in python

我是这个论坛的新手,所以我不太了解这里的规则和提交模板。对不起,如果我做错了。

所以我的问题是我有一个代码可以让 2 AI 玩 Tic Tac Toe。这是游戏的输出。

| × |欧 | X |

| × |欧 | X |

|欧 |欧 | X |

我需要向观众展示它,并希望以更图形化的形式展示我的输出,如下所示:

Tic Tac Toe graphical version

所以我的问题是,如何将输出转换为图形版本?

感谢帮助我

我建议你看看一些 GUI 库,比如 Qt、Kivy、pygame... 我发现 tkinter 是最容易使用的方法之一,here's 专门针对 tic-tac-toe 的教程。

from tkinter import *
from tkinter import messagebox
count=0
board=[[‘’,’’,’’,],
 [‘’,’’,’’,],
 [‘’,’’,’’,]]

def TicTacToeGUI():
    global t
    t=Tk()
    t.title("TIC TAC TOE")
    t.configure(bg="white")  
    #Making the background of the window as white#Displaying the player
    l1=Label(t,text="PLAYER: 1(X)",height=3,font=("COMIC SANS MS",10,"bold"),bg="white")
    l1.grid(row=0,column=0)#Quit button
    exitButton=Button(t,text="Quit",command=Quit,font=("COMIC SANS MS",10,"bold"))
    exitButton.grid(row=0,column=2)#Grid buttons
    b1=Button(t,text="",height=4,width=8,bg="black",activebackground="white",fg="white",font="Times 15 bold",command=lambda: changeVal(b1,0,0))
    b2=Button(t,text="",height=4,width=8,bg="black",activebackground="white",fg="white",font="Times 15 bold",command=lambda: changeVal(b2,0,1))
    b3=Button(t,text="",height=4,width=8,bg="black",activebackground="white",fg="white",font="Times 15 bold",command=lambda: changeVal(b3,0,2))
    b4=Button(t,text="",height=4,width=8,bg="black",activebackground="white",fg="white",font="Times 15 bold",command=lambda: changeVal(b4,1,0))
    b5=Button(t,text="",height=4,width=8,bg="black",activebackground="white",fg="white",font="Times 15 bold",command=lambda: changeVal(b5,1,1))
    b6=Button(t,text="",height=4,width=8,bg="black",activebackground="white",fg="white",font="Times 15 bold",command=lambda: changeVal(b6,1,2))
    b7=Button(t,text="",height=4,width=8,bg="black",activebackground="white",fg="white",font="Times 15 bold",command=lambda: changeVal(b7,2,0))
    b8=Button(t,text="",height=4,width=8,bg="black",activebackground="white",fg="white",font="Times 15 bold",command=lambda: changeVal(b8,2,1))
    b9=Button(t,text="",height=4,width=8,bg="black",activebackground="white",fg="white",font="Times 15 bold",command=lambda: changeVal(b9,2,2))
    b1.grid(row=2,column=0)
    b2.grid(row=2,column=1)
    b3.grid(row=2,column=2)b4.grid(row=3,column=0)
    b5.grid(row=3,column=1)
    b6.grid(row=3,column=2)b7.grid(row=4,column=0)
    b8.grid(row=4,column=1)
    b9.grid(row=4,column=2)