{"id":18603969,"url":"https://github.com/farzeennimran/tic-tac-toe-game-gui-using-tkinter-python","last_synced_at":"2025-10-14T08:34:36.534Z","repository":{"id":244124541,"uuid":"814337422","full_name":"farzeennimran/Tic-Tac-Toe-Game-GUI-using-tkinter-python","owner":"farzeennimran","description":"Tic Tac Toe game with a GUI using Tkinter in Python 🕹️","archived":false,"fork":false,"pushed_at":"2024-07-01T12:26:27.000Z","size":25,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-09T16:45:58.684Z","etag":null,"topics":["alpha-beta-pruning","artificial-intelligence","data-science","game","gui","python","tic-tac-toe","tkinter-graphic-interface","tkinter-python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/farzeennimran.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-12T20:10:30.000Z","updated_at":"2024-07-01T12:26:47.000Z","dependencies_parsed_at":"2024-06-15T12:33:21.797Z","dependency_job_id":"dddc4c99-b4d8-42ee-b1ce-c144527eb340","html_url":"https://github.com/farzeennimran/Tic-Tac-Toe-Game-GUI-using-tkinter-python","commit_stats":null,"previous_names":["farzeennimran/tic-tac-toe-game-gui-using-tkinter-python"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/farzeennimran/Tic-Tac-Toe-Game-GUI-using-tkinter-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farzeennimran%2FTic-Tac-Toe-Game-GUI-using-tkinter-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farzeennimran%2FTic-Tac-Toe-Game-GUI-using-tkinter-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farzeennimran%2FTic-Tac-Toe-Game-GUI-using-tkinter-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farzeennimran%2FTic-Tac-Toe-Game-GUI-using-tkinter-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/farzeennimran","download_url":"https://codeload.github.com/farzeennimran/Tic-Tac-Toe-Game-GUI-using-tkinter-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farzeennimran%2FTic-Tac-Toe-Game-GUI-using-tkinter-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018307,"owners_count":26086342,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alpha-beta-pruning","artificial-intelligence","data-science","game","gui","python","tic-tac-toe","tkinter-graphic-interface","tkinter-python"],"created_at":"2024-11-07T02:16:06.219Z","updated_at":"2025-10-14T08:34:36.513Z","avatar_url":"https://github.com/farzeennimran.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tic Tac Toe Game GUI using Tkinter and Alpha-Beta Pruning \n\n## Introduction\n\nThis project implements a Tic Tac Toe game with a graphical user interface (GUI) using Tkinter in Python. The game uses the Minimax algorithm with Alpha-Beta Pruning to provide an AI opponent that makes optimal moves. The GUI allows players to interact with the game easily, making it a fun and engaging way to play Tic Tac Toe against an AI.\n\n## Alpha-Beta Pruning in Minimax Algorithm\n\nAlpha-Beta Pruning is an optimization technique for the Minimax algorithm. It reduces the number of nodes evaluated by the Minimax algorithm in its search tree, allowing it to search deeper and make more efficient decisions. The idea is to eliminate branches in the game tree that do not need to be explored because they cannot affect the final decision. \n\nHere's a high-level overview of how Alpha-Beta Pruning is used in this project:\n\n1. **Minimax Algorithm**: This algorithm evaluates all possible moves to determine the optimal one by simulating the game to the end.\n2. **Alpha-Beta Pruning**: During the Minimax evaluation, Alpha (the best value the maximizing player can guarantee) and Beta (the best value the minimizing player can guarantee) are used to cut off branches that don't need to be explored.\n\n## GUI using Tkinter\n\nTkinter is the standard Python library for creating graphical user interfaces. It is used here to create a simple, interactive interface for the Tic Tac Toe game.\n\n### Key Components of the GUI\n\n- **Root Window**: The main window of the application.\n- **Buttons**: Each cell of the Tic Tac Toe board is represented by a button.\n- **Message Box**: Displays the game result when the game ends.\n\n![image](https://github.com/farzeennimran/Tic-Tac-Toe-Game-GUI-using-tkinter-python/assets/136755585/40584158-6f69-46e4-9033-9a84d9581a49)\n\n![game over](https://github.com/farzeennimran/Tic-Tac-Toe-Game-GUI-using-tkinter-python/assets/136755585/767c7074-9f5a-411d-933e-6a15272f6f35)\n\n## Code Explanation\n\n### Importing Libraries\n\n```python\nimport copy\nimport math\nimport tkinter as tk\nfrom tkinter import messagebox\n```\n\n### Constants\n\n```python\nX = \"X\"\nO = \"O\"\nEMPTY = None\n```\n\n### Game Logic Functions\n\n- **Initial State**: Returns the initial empty board.\n- **Player**: Determines whose turn it is.\n- **Actions**: Returns the set of possible actions.\n- **Result**: Returns the board resulting from a move.\n- **Winner**: Determines the winner of the game.\n- **Terminal**: Checks if the game is over.\n- **Utility**: Returns the utility value of a terminal state.\n- **Minimax with Alpha-Beta Pruning**: Determines the optimal move for the current player.\n\n### GUI Class\n\n#### Initialization\n\nThe `TicTacToeGUI` class initializes the main window, the board, and the buttons:\n\n```python\nclass TicTacToeGUI:\n    def __init__(self, root):\n        self.root = root\n        self.root.title(\"Tic Tac Toe\")\n        self.root.configure(bg='light blue')\n        self.board = initial_state()\n        self.buttons = [[None for _ in range(3)] for _ in range(3)]\n        self.create_buttons()\n        self.update_buttons()\n```\n\n#### Creating Buttons\n\nButtons for each cell are created and placed on the grid:\n\n```python\ndef create_buttons(self):\n    for i in range(3):\n        for j in range(3):\n            button = tk.Button(self.root, text='', font=('normal', 40), width=5, height=2, bg='light blue', command=lambda row=i, col=j: self.on_button_click(row, col))\n            button.grid(row=i, column=j)\n            self.buttons[i][j] = button\n```\n\n#### Button Click Handler\n\nHandles the logic when a button (cell) is clicked:\n\n```python\ndef on_button_click(self, row, col):\n    if self.board[row][col] == EMPTY and not terminal(self.board):\n        self.board = result(self.board, (row, col))\n        self.update_buttons()\n        if terminal(self.board):\n            self.end_game()\n            return\n        self.board = result(self.board, minimax(self.board, -math.inf, math.inf))\n        self.update_buttons()\n        if terminal(self.board):\n            self.end_game()\n```\n\n#### Updating Buttons\n\nUpdates the button text to reflect the current board state:\n\n```python\ndef update_buttons(self):\n    for i in range(3):\n        for j in range(3):\n            if self.board[i][j] == X:\n                self.buttons[i][j].config(text='X', state='disabled')\n            elif self.board[i][j] == O:\n                self.buttons[i][j].config(text='O', state='disabled')\n            else:\n                self.buttons[i][j].config(text='', state='normal')\n```\n\n#### End Game Handling\n\nDisplays the game result and resets the board:\n\n```python\ndef end_game(self):\n    winner_val = winner(self.board)\n    if winner_val:\n        messagebox.showinfo(\"Game Over\", f\"Winner: {winner_val}\")\n    else:\n        messagebox.showinfo(\"Game Over\", \"It's a tie!\")\n    self.reset_board()\n\ndef reset_board(self):\n    self.board = initial_state()\n    self.update_buttons()\n```\n\n### Main Loop\n\nRuns the Tkinter main loop to start the game:\n\n```python\nif __name__ == \"__main__\":\n    root = tk.Tk()\n    game = TicTacToeGUI(root)\n    root.mainloop()\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarzeennimran%2Ftic-tac-toe-game-gui-using-tkinter-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffarzeennimran%2Ftic-tac-toe-game-gui-using-tkinter-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarzeennimran%2Ftic-tac-toe-game-gui-using-tkinter-python/lists"}