pythontic-tac-toegraphical-programming

Shaping a tic tac toe in python


I'm new to this forum, so I don't really know the rules and the submission template here. sorry if i do some mistakes.

So my problem is that I have a code that makes 2 AI play Tic Tac Toe. Here is the output of the game.

| X | O | X |

| X | O | X |

| O | O | X |

And I need to present this to an audience and would like to present my output in a more graphical version like this:

Tic Tac Toe graphical version

So my question is, how do I turn my output into my graphical version?

Thanks to help me


Solution

  • I suggest you to give a look at some GUI libraries like Qt, Kivy, pygame... I find tkinter to be one of the easiest to work with, here's a tutorial about tic-tac-toe specifically.

    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)