{"id":21676887,"url":"https://github.com/rasbeetech/myminesweeper_tkinter","last_synced_at":"2025-10-05T09:44:32.185Z","repository":{"id":135281982,"uuid":"342309729","full_name":"RasbeeTech/myMinesweeper_Tkinter","owner":"RasbeeTech","description":"Tkinter Framework application","archived":false,"fork":false,"pushed_at":"2021-03-30T22:57:18.000Z","size":85,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-05T09:44:31.268Z","etag":null,"topics":["python","tkinter"],"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/RasbeeTech.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":"2021-02-25T16:36:17.000Z","updated_at":"2021-04-14T01:02:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"4ba799c5-b375-41b3-a3a2-9870e1891ec4","html_url":"https://github.com/RasbeeTech/myMinesweeper_Tkinter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/RasbeeTech/myMinesweeper_Tkinter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RasbeeTech%2FmyMinesweeper_Tkinter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RasbeeTech%2FmyMinesweeper_Tkinter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RasbeeTech%2FmyMinesweeper_Tkinter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RasbeeTech%2FmyMinesweeper_Tkinter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RasbeeTech","download_url":"https://codeload.github.com/RasbeeTech/myMinesweeper_Tkinter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RasbeeTech%2FmyMinesweeper_Tkinter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278437956,"owners_count":25986760,"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-05T02:00:06.059Z","response_time":54,"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":["python","tkinter"],"created_at":"2024-11-25T14:16:45.210Z","updated_at":"2025-10-05T09:44:32.163Z","avatar_url":"https://github.com/RasbeeTech.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# myMinesweeper_Tkinter\n\n A simple 10x10 Minesweeper game\n \n Python version: 3.8.7\n\n TkInter is used to create the graphical user interface\n \n ## Sample:\n Game play                    |  Game over\n :-------------------------:|:-------------------------: \n ![alt text](https://github.com/RasbeeTech/Minesweeper/blob/main/sample_image.jpeg) | ![alt text](https://github.com/RasbeeTech/Minesweeper/blob/main/sample_image_2.jpeg)\n \n To see finished program code, click [here](https://github.com/RasbeeTech/Minesweeper/blob/main/minesweeper.py)  \n \n ## Minesweeper rules\n The rules of the game are fairly simple.  Uncover tiles and use indicators to avoid mines.  To win, uncover all tiles that do not have mines.  The numbered indicators represent the amount of mines in the adjacent tiles.\n \n ## How to play\n * Left-click: tile to reveal tile.  \n * Right-click: to flag mine locations.  \n \n ## Process:\n 1.\tCreate a tkinter window.\n ```python\n import tkinter as tk\n \n root = tk.Tk() # Creates tkinter window\n root.mainloop() # Runs window\n ```\n 2.\tCreate tkinter labels and arrange them using grid() (I accomplished this by using a nested while loop).\n \t\tNote: Be sure to save labels where the can be accessed later.\n ```python\n tiles = []\n rows = 10\n cols = 10\n\n x = 0\n # A nested loop creates 2 dimensional array or a grid\n while x \u003c cols:\n \ty = 0\n \ttile = []\n \t# creates tiles by rows\n \twhile y \u003c rows: \n \t\t# Labels serve as tiles for the game\n \t\ttile.append(tk.Label(text=\"\", bg=\"green\", height=\"2\", width=\"4\", borderwidth=5, relief=\"raised\"))\n \t\ttile[y].bind(\"\u003cButton-1\u003e\", left_click)\n \t\ttile[y].bind(\"\u003cButton-2\u003e\", right_click)\n \t\ttile[y].grid(row=x, column=y)\n \t\ty += 1\n \t# adds the created row of row of labels to the tiles[]\n \ttiles.append(tile)\n \tx += 1\n ```\n 3.\tBind left-click and right-click event functions to each label.\n \t\tLeft-click reveals() tile and adjacent tiles.\n \t\tRight-click sets flags tile.\n ```python\n def right_click(event):\n \tif not is_game_over:\n        column = event.widget.grid_info()[\"column\"]\n        row = event.widget.grid_info()[\"row\"]\n\n        if[row,column] not in revealed:\n            event.widget.config(text=\"X\")\n def left_click(event):\n\tif not is_game_over:\n\t\tcolumn = event.widget.grid_info()[\"column\"]\n        row = event.widget.grid_info()[\"row\"]\n        reveal(row, column)\n        if len(revealed) == to_win:\n            you_win()\n ```\n 4. Using random number generator, get x and y locations to place mines.\n ```python\n from random import randrange\n \n def set_bombs():\n    bomb_tiles = []\n    bombs_planted = 0\n\tnum_of_bombs = 10\n\t\n\t# Will set 10 mines on playing field in random locations\n    while bombs_planted \u003c num_of_bombs:\n    \t# randrange(10): randomly generates a integer between 0 and 9 to be used for location of mines\n    \trow = randrange(10)\n        col = randrange(10)\n        # If statement checks if mine is already placed in a location already\n        if [row, col] not in bomb_tiles:\n        \tbomb_tiles.append([row, col])\n        \tbombs_planted += 1\n ```\n 5. Create a function to check adjacent tiles.\n ```python\n # Takes location of a tile and applies function to all adjacent tiles\n def check_adjacent_tiles(row, column, func):\n \tr = row\n \tc = column\n    if row == 0 and column == 0:\n    \tfunc(row, column + 1)\n        func(row + 1, column)\n        func(row + 1, column + 1)\n    elif row == 9 and column == 9:\n        func(row - 1, column)\n        func(row - 1, column - 1)\n        func(row, column - 1)\n    elif row == 0 and column == 9:\n        func(row, column - 1)\n        func(row + 1, column - 1)\n        func(row + 1, column)\n    elif row == 9 and column == 0:\n        func(row - 1, column)\n        func(row - 1, column + 1)\n        func(row, column + 1)\n    elif row == 0:\n        func(row, column - 1)\n        func(row, column + 1)\n        func(row + 1, column - 1)\n        func(row + 1, column)\n        func(row + 1, column + 1)\n    elif row == 9:\n        func(row - 1, column)\n        func(row - 1, column - 1)\n        func(row - 1, column + 1)\n        func(row, column - 1)\n        func(row, column + 1)\n    elif column == 0:\n        func(row - 1, column)\n        func(row - 1, column + 1)\n        func(row, column + 1)\n        func(row + 1, column)\n        func(row + 1, column + 1)\n    elif column == 9:\n        func(row - 1, column)\n        func(row - 1, column - 1)\n        func(row, column - 1)\n        func(row + 1, column - 1)\n        func(row + 1, column)\n    else:\n        func(row - 1, column)\n        func(row - 1, column - 1)\n        func(row - 1, column + 1)\n        func(row, column - 1)\n        func(row, column + 1)\n        func(row + 1, column - 1)\n        func(row + 1, column)\n        func(row + 1, column + 1)\n ```\n 6. Create function to set indicators for bomb locations when tile is revealed.\n ```python\n indicators = []\n \n def set_indicators():\n    for bomb in bomb_tiles:\n    # using method to check adjacent tiles the uses the get_idicators() function to add them to the indicators list.\n    check_adjacent_tiles(bomb[0], bomb[1], get_indicators)\n    \n def get_indicators(row, column):\n \t# Make sure not to set indicators on top of a mine\n\tif [row, column] not in bomb_tiles:\n    \tindicators.append([row, column])\n ```\n 7.\tFinally, create actions for when the game is Win and Lose.\n ```python\n def game_over():\n\tis_game_over = True\n\tfor bomb in bomb_tiles:\n\t\ttiles[bomb[0]][bomb[1]].config(bg=\"red\")\n    # new_game() is a function that makes a pop-up window that asks if you would like to try again\n    new_game(window, \"Game Over\")\n        \n def you_win():\n\tnew_game(window, \"YOU WIN!\")\n ```\n \t\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frasbeetech%2Fmyminesweeper_tkinter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frasbeetech%2Fmyminesweeper_tkinter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frasbeetech%2Fmyminesweeper_tkinter/lists"}