GithubHelp home page GithubHelp logo

xox-using-tkinter's Introduction

Tick Tack Toe

we developed a Simpale Tick Tack Toe Desktop game

installation

  • python

    Click here to download python3

  • pip

Open cmd then type

  python get-pip.py
  • Tinker

Open cmd then type

    pip install tk

Pre-requisites:

Python3, pip,Tinker

Approch

  • Tinker is implemented for GUI

Code

from tkinter import *

from tkinter import messagebox

window = Tk()

#window size

window.geometry("500x500")

#Title Of Game

window.title("XOX")

#Equely Dived Window 

row_1 = Frame(window,bg="#fff",)
row_1.pack(expand=True,fill="both")

row_2 = Frame(window)
row_2.pack(expand=True,fill="both",)

row_3 = Frame(window,bg="#fff",)
row_3.pack(expand=True,fill="both")
click = True
def logic(buttons):
    
    global click
    
    #cheaking

    if buttons["text"]=="" and click==True:
        buttons["text"]="X"
        click = False 
        

    elif buttons["text"]=="" and click==False:
        buttons["text"]="O"
        click = True
        
    if(btn_1["text"]=="O" and btn_2["text"]=="O" and btn_3["text"]=="O" or
    btn_4["text"]=="O" and btn_5["text"]=="O" and btn_6["text"]=="O" or
    btn_7["text"]=="O" and btn_8["text"]=="O" and btn_9["text"]=="O" or
    btn_1["text"]=="O" and btn_5["text"]=="O" and btn_9["text"]=="O" or
    btn_1["text"]=="O" and btn_7["text"]=="O" and btn_4["text"]=="O" or
    btn_5["text"]=="O" and btn_2["text"]=="O" and btn_8["text"]=="O" or
    btn_9["text"]=="O" and btn_6["text"]=="O" and btn_3["text"]=="O" or 
    btn_3["text"]=="O" and btn_5["text"]=="O" and btn_7["text"]=="O"):

         messagebox.showinfo("Winner O", "Player 2 You Have Just Won The Game")
         
         exit()

    if (btn_1["text"]=="X" and btn_2["text"]=="X" and btn_3["text"]=="X" or 
    btn_4["text"]=="X" and btn_5["text"]=="X" and btn_6["text"]=="X" or 
    btn_7["text"]=="X" and btn_8["text"]=="X" and btn_9["text"]=="X" or 
    btn_1["text"]=="X" and btn_5["text"]=="X" and btn_9["text"]=="X" or 
    btn_1["text"]=="X" and btn_7["text"]=="X" and btn_4["text"]=="X" or 
    btn_5["text"]=="X" and btn_2["text"]=="X" and btn_8["text"]=="X" or 
    btn_9["text"]=="X" and btn_6["text"]=="X" and btn_3["text"]=="X" or 
    btn_3["text"]=="X" and btn_5["text"]=="X" and btn_7["text"]=="X"):
            
        messagebox.showinfo("Winner X", "Player 1 You Have Just Won The Game")            

        exit()

#Button Designed

btn_1=Button(
    row_1,
    command=lambda:logic(btn_1)

)
btn_1.pack(side=LEFT,

expand=True,

fill="both",
)

btn_2=Button(
    row_1,
    command= lambda:logic(btn_2)
    )
btn_2.pack(side=LEFT,expand=True,fill="both",)

btn_3=Button(row_1,command=lambda:logic(btn_3))
btn_3.pack(side=LEFT,expand=True,fill="both")

btn_4=Button(row_2,command=lambda:logic(btn_4))
btn_4.pack(side=LEFT,expand=True,fill="both")

btn_5=Button(row_2,command=lambda:logic(btn_5))
btn_5.pack(side=LEFT,expand=True,fill="both")

btn_6=Button(row_2,command=lambda:logic(btn_6))
btn_6.pack(side=LEFT,expand=True,fill="both")

btn_7=Button(row_3,command=lambda:logic(btn_7))
btn_7.pack(side=LEFT,expand=True,fill="both")

btn_8=Button(row_3,command=lambda:logic(btn_8))
btn_8.pack(side=LEFT,expand=True,fill="both")

btn_9=Button(row_3,command=lambda:logic(btn_9))
btn_9.pack(side=LEFT,expand=True,fill="both")

window.mainloop()

Run code

Open cmd then type

    python xox.py

Screenshot

1

2n

4n

3n

xox-using-tkinter's People

Contributors

nizamkolathoden avatar sabithk avatar

Stargazers

Thasli avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.