└── ChatGPT API Ultimate Beginners Guide.ipynb /ChatGPT API Ultimate Beginners Guide.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "ff5d3f34", 6 | "metadata": {}, 7 | "source": [ 8 | "# How to Create Your ChatGPT API Apps" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 5, 14 | "id": "8f67855b", 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "Requirement already satisfied: openai in /Users/liamottley/opt/anaconda3/lib/python3.9/site-packages (0.27.0)\r\n", 22 | "Requirement already satisfied: requests>=2.20 in /Users/liamottley/opt/anaconda3/lib/python3.9/site-packages (from openai) (2.28.1)\r\n", 23 | "Requirement already satisfied: aiohttp in /Users/liamottley/opt/anaconda3/lib/python3.9/site-packages (from openai) (3.8.4)\r\n", 24 | "Requirement already satisfied: tqdm in /Users/liamottley/opt/anaconda3/lib/python3.9/site-packages (from openai) (4.64.1)\r\n", 25 | "Requirement already satisfied: idna<4,>=2.5 in /Users/liamottley/opt/anaconda3/lib/python3.9/site-packages (from requests>=2.20->openai) (3.3)\r\n", 26 | "Requirement already satisfied: certifi>=2017.4.17 in /Users/liamottley/opt/anaconda3/lib/python3.9/site-packages (from requests>=2.20->openai) (2022.9.24)\r\n", 27 | "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/liamottley/opt/anaconda3/lib/python3.9/site-packages (from requests>=2.20->openai) (1.26.11)\r\n", 28 | "Requirement already satisfied: charset-normalizer<3,>=2 in /Users/liamottley/opt/anaconda3/lib/python3.9/site-packages (from requests>=2.20->openai) (2.0.4)\r\n", 29 | "Requirement already satisfied: frozenlist>=1.1.1 in /Users/liamottley/opt/anaconda3/lib/python3.9/site-packages (from aiohttp->openai) (1.3.3)\r\n", 30 | "Requirement already satisfied: attrs>=17.3.0 in /Users/liamottley/opt/anaconda3/lib/python3.9/site-packages (from aiohttp->openai) (21.4.0)\r\n", 31 | "Requirement already satisfied: multidict<7.0,>=4.5 in /Users/liamottley/opt/anaconda3/lib/python3.9/site-packages (from aiohttp->openai) (6.0.4)\r\n", 32 | "Requirement already satisfied: aiosignal>=1.1.2 in /Users/liamottley/opt/anaconda3/lib/python3.9/site-packages (from aiohttp->openai) (1.3.1)\r\n", 33 | "Requirement already satisfied: yarl<2.0,>=1.0 in /Users/liamottley/opt/anaconda3/lib/python3.9/site-packages (from aiohttp->openai) (1.8.2)\r\n", 34 | "Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /Users/liamottley/opt/anaconda3/lib/python3.9/site-packages (from aiohttp->openai) (4.0.2)\r\n" 35 | ] 36 | } 37 | ], 38 | "source": [ 39 | "!pip install openai" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 6, 45 | "id": "3186ce6b", 46 | "metadata": {}, 47 | "outputs": [], 48 | "source": [ 49 | "import openai\n", 50 | "openai.api_key = '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'" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "id": "ba282147", 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "# METHOD 1: Python Library\n", 61 | "\n", 62 | "# Create your messages list\n", 63 | "messages = [\n", 64 | " {\"role\": \"system\", \"content\": \"You are a kind helpful assistant.\"},\n", 65 | "]\n", 66 | "\n", 67 | "# Open a loop to begin chatting\n", 68 | "while True:\n", 69 | " message = input(\"User : \")\n", 70 | " if message:\n", 71 | " messages.append(\n", 72 | " {\"role\": \"user\", \"content\": message},\n", 73 | " )\n", 74 | " chat = openai.ChatCompletion.create(\n", 75 | " model=\"gpt-3.5-turbo\", messages=messages\n", 76 | " )\n", 77 | " \n", 78 | " reply = chat.choices[0].message.content\n", 79 | " print(f\"ChatGPT: {reply}\")\n", 80 | " messages.append({\"role\": \"assistant\", \"content\": reply})" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 11, 86 | "id": "350188d1", 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "name": "stdout", 91 | "output_type": "stream", 92 | "text": [ 93 | "{'choices': [{'finish_reason': 'stop',\n", 94 | " 'index': 0,\n", 95 | " 'message': {'content': 'The Empire State Building is a very tall '\n", 96 | " 'skyscraper located in New York City, '\n", 97 | " 'USA. It was completed in 1931 and was '\n", 98 | " 'the tallest building in the world until '\n", 99 | " '1971. It is a popular tourist attraction '\n", 100 | " 'and has observation decks on the 86th '\n", 101 | " 'and 102nd floors, which offer stunning '\n", 102 | " 'views of the city.',\n", 103 | " 'role': 'assistant'}}],\n", 104 | " 'created': 1678442853,\n", 105 | " 'id': 'chatcmpl-6sTwr29MBeQX0YBWJJlw7sDXr0DT4',\n", 106 | " 'model': 'gpt-3.5-turbo-0301',\n", 107 | " 'object': 'chat.completion',\n", 108 | " 'usage': {'completion_tokens': 69, 'prompt_tokens': 32, 'total_tokens': 101}}\n" 109 | ] 110 | } 111 | ], 112 | "source": [ 113 | "# METHOD 2: Using API Endpoint\n", 114 | "\n", 115 | "import requests\n", 116 | "import pprint\n", 117 | "\n", 118 | "URL = \"https://api.openai.com/v1/chat/completions\"\n", 119 | "\n", 120 | "# Create your messages list\n", 121 | "messages = [\n", 122 | " {\"role\": \"system\", \"content\": \"You are a kind helpful assistant who is 5 years old.\"},\n", 123 | " {\"role\": \"user\", \"content\": \"What is the empire state building?\"}\n", 124 | "]\n", 125 | "\n", 126 | "payload = {\n", 127 | "\"model\": \"gpt-3.5-turbo\",\n", 128 | "\"messages\": messages,\n", 129 | "\"temperature\" : 0.1,\n", 130 | "\"top_p\":1.0,\n", 131 | "\"n\" : 1,\n", 132 | "\"stream\": False,\n", 133 | "\"presence_penalty\":0,\n", 134 | "\"frequency_penalty\":0,\n", 135 | "}\n", 136 | "\n", 137 | "headers = {\n", 138 | "\"Content-Type\": \"application/json\",\n", 139 | "\"Authorization\": \"Bearer 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\"\n", 140 | "}\n", 141 | "\n", 142 | "response = requests.post(URL, headers=headers, json=payload, stream=False)\n", 143 | "\n", 144 | "pprint.pprint(response.json())" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 13, 150 | "id": "6a96eab9", 151 | "metadata": {}, 152 | "outputs": [], 153 | "source": [ 154 | "# Create Chatbot function, just insert messages\n", 155 | "def chat(messages):\n", 156 | " while True:\n", 157 | " message = input(\"User : \")\n", 158 | " if message:\n", 159 | " messages.append(\n", 160 | " {\"role\": \"user\", \"content\": message},\n", 161 | " )\n", 162 | " chat = openai.ChatCompletion.create(\n", 163 | " model=\"gpt-3.5-turbo\", messages=messages\n", 164 | " )\n", 165 | "\n", 166 | " reply = chat.choices[0].message.content\n", 167 | " print(f\"Tutor: {reply}\")\n", 168 | " messages.append({\"role\": \"assistant\", \"content\": reply})" 169 | ] 170 | }, 171 | { 172 | "cell_type": "markdown", 173 | "id": "fe866702", 174 | "metadata": {}, 175 | "source": [ 176 | "# Example 1: Coding Coach" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": 14, 182 | "id": "5e243a1b", 183 | "metadata": {}, 184 | "outputs": [ 185 | { 186 | "name": "stdout", 187 | "output_type": "stream", 188 | "text": [ 189 | "User : Hi I'm here to learn python. My name is Liam\n", 190 | "Tutor: Hi Liam! Welcome to your Python tutorial. I am happy to help you learn the language. What are some things you hope to accomplish in this tutorial?\n", 191 | "User : Start from the basics, I know nothing!\n", 192 | "Tutor: Sure thing! Let's start with the very basics of Python.\n", 193 | "\n", 194 | "Firstly, can you tell me what do you think Python is and why it is such a popular programming language?\n", 195 | "User : I know it can be used for machine learning and quick scripts, that's about it\n", 196 | "Tutor: That's a good start! Python is a high-level, interpreted programming language that is known for its simplicity, readability, and ease of use. It has a vast number of libraries and frameworks which make it versatile and able to be used in a wide range of fields, such as data analytics, web development, scientific computing, machine learning, artificial intelligence, and more! It is also open source and has a large, active community of users who are willing to share knowledge and help others. \n", 197 | "\n", 198 | "Now that you have an idea of what Python is, the first thing you need to do is to install it on your computer. Have you done that yet or do you need help with that?\n", 199 | "User : Some help would be great!\n", 200 | "Tutor: Sure! Here are the steps to install Python on your computer:\n", 201 | "\n", 202 | "1. Go to the official Python website: www.python.org\n", 203 | "2. Click on the \"Downloads\" tab at the top of the page.\n", 204 | "3. Scroll down until you see \"Python Releases for Windows\" or \"Python Releases for Mac OS X\", depending on your operating system.\n", 205 | "4. Download the latest version of Python by clicking on the appropriate link.\n", 206 | "5. Run the installer and follow the instructions.\n", 207 | "\n", 208 | "Once you have installed Python on your computer, you can open the Python interpreter and start coding. On a Windows machine, you can open the interpreter by clicking \"Python\" in the Start Menu. On a Mac, you can open the Terminal app and type \"python\" to open the interpreter.\n", 209 | "\n", 210 | "Let me know if you run into any issues with the installation!\n" 211 | ] 212 | }, 213 | { 214 | "ename": "KeyboardInterrupt", 215 | "evalue": "Interrupted by user", 216 | "output_type": "error", 217 | "traceback": [ 218 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 219 | "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", 220 | "\u001b[0;32m/var/folders/yq/p3rq32mj7j9532rbbmhqhsr40000gn/T/ipykernel_18418/158832653.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 23\u001b[0m \u001b[0;31m# Use chat function, add in messages\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 24\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 25\u001b[0;31m \u001b[0mchat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmessages\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 221 | "\u001b[0;32m/var/folders/yq/p3rq32mj7j9532rbbmhqhsr40000gn/T/ipykernel_18418/2945404508.py\u001b[0m in \u001b[0;36mchat\u001b[0;34m(messages)\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mchat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmessages\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mwhile\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mmessage\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0minput\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"User : \"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mmessage\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m messages.append(\n", 222 | "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/ipykernel/kernelbase.py\u001b[0m in \u001b[0;36mraw_input\u001b[0;34m(self, prompt)\u001b[0m\n\u001b[1;32m 1175\u001b[0m \u001b[0;34m\"raw_input was called, but this frontend does not support input requests.\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1176\u001b[0m )\n\u001b[0;32m-> 1177\u001b[0;31m return self._input_request(\n\u001b[0m\u001b[1;32m 1178\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mprompt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1179\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_parent_ident\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"shell\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 223 | "\u001b[0;32m~/opt/anaconda3/lib/python3.9/site-packages/ipykernel/kernelbase.py\u001b[0m in \u001b[0;36m_input_request\u001b[0;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[1;32m 1217\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1218\u001b[0m \u001b[0;31m# re-raise KeyboardInterrupt, to truncate traceback\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1219\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Interrupted by user\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1220\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1221\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlog\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwarning\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Invalid Message:\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexc_info\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 224 | "\u001b[0;31mKeyboardInterrupt\u001b[0m: Interrupted by user" 225 | ] 226 | } 227 | ], 228 | "source": [ 229 | "# Create your messages list\n", 230 | "messages = [\n", 231 | " {\n", 232 | " \"role\": \"system\", \"content\": \"\"\"\n", 233 | " You are a programming tutor who is helping the user learn the Basics of Python. \n", 234 | " You need to ask the user questions to help them understand the language and give them challenges they must complete. \n", 235 | " They can paste in their code for you to check. \n", 236 | " You need to progress them into more and more difficult theory and practical examples over time.\n", 237 | " \"\"\"\n", 238 | " },\n", 239 | " {\n", 240 | " \"role\": \"user\", \"content\": \"\"\"\n", 241 | " You are a programming tutor who is helping the user learn the Basics of Python. \n", 242 | " You need to ask the user questions to help them understand the language and give them challenges they must complete. \n", 243 | " They can paste in their code for you to check. \n", 244 | " You need to progress them into more and more difficult theory and practical examples over time. \n", 245 | " Do you understand?\n", 246 | " \"\"\"\n", 247 | " },\n", 248 | " {\"role\": \"assistant\", \"content\": \"Yes I understand.\"}\n", 249 | "]\n", 250 | "\n", 251 | "# Use chat function, add in messages\n", 252 | "chat(messages)" 253 | ] 254 | }, 255 | { 256 | "cell_type": "markdown", 257 | "id": "2c575e24", 258 | "metadata": {}, 259 | "source": [ 260 | "# Example 2: Personalized Email Responder" 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": null, 266 | "id": "4e8d2ecc", 267 | "metadata": {}, 268 | "outputs": [], 269 | "source": [ 270 | "# Create your messages list\n", 271 | "messages = [\n", 272 | " {\n", 273 | " \"role\": \"system\", \"content\": \"\"\"\n", 274 | " You are a helpful personalized email writing assistant.\n", 275 | " The user provides you with previous examples of their emails and you can copy their style when they provide you with an email they have receieved. \n", 276 | " \"\"\"\n", 277 | " },\n", 278 | " {\"role\": \"user\", \"content\": \"Hi, I need you to help me automate my emails. I need you to reply in my own style. I will give you some examples of my own emails for you to learn my style from. Is that ok?\"},\n", 279 | " {\"role\": \"assistant\", \"content\": \"Yes of course. Please provide the examples you'd like me to learn from!\"},\n", 280 | " {\"role\": \"user\", \"content\": \"\"\"\n", 281 | " Here they are: \n", 282 | " \n", 283 | " REMOVED MY PERSONAL EMAIL EXAMPLES HERE. ADD YOUR OWN!!!\n", 284 | " \n", 285 | " \"\"\"\n", 286 | " }\n", 287 | "]\n", 288 | "\n", 289 | "# Open a loop to begin chatting\n", 290 | "chat(messages)" 291 | ] 292 | }, 293 | { 294 | "cell_type": "markdown", 295 | "id": "59ff1cb2", 296 | "metadata": {}, 297 | "source": [ 298 | "# Example 3: Game Developer Tool" 299 | ] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "execution_count": null, 304 | "id": "fd2c4673", 305 | "metadata": {}, 306 | "outputs": [], 307 | "source": [ 308 | "# Create your messages list\n", 309 | "messages = [\n", 310 | " {\n", 311 | " \"role\": \"system\", \"content\": \"\"\"\n", 312 | " You are a game developer. You generate python scripts for games based on what people describe to you.\n", 313 | " \"\"\"\n", 314 | " },\n", 315 | " {\"role\": \"user\", \"content\": \"Hi, I need you to help me create a game in Python. I will describe the game to you and you will give me back a script for it. Be sure to always include code for a GUI that appears for me to play the game on. Is that ok?\"},\n", 316 | " {\"role\": \"assistant\", \"content\": \"Yes of course. Please provide me with some details on this game!\"},\n", 317 | "]\n", 318 | "\n", 319 | "# Open a loop to begin chatting\n", 320 | "chat(messages)" 321 | ] 322 | }, 323 | { 324 | "cell_type": "code", 325 | "execution_count": 20, 326 | "id": "185c9e13", 327 | "metadata": {}, 328 | "outputs": [], 329 | "source": [ 330 | "import tkinter as tk\n", 331 | "\n", 332 | "class TicTacToeGUI:\n", 333 | " def __init__(self):\n", 334 | " self.window = tk.Tk()\n", 335 | " self.window.title(\"Tic Tac Toe\")\n", 336 | " self.window.geometry(\"300x300\")\n", 337 | " \n", 338 | " self.current_player = \"X\"\n", 339 | " self.board = [[\"\", \"\", \"\"], [\"\", \"\", \"\"], [\"\", \"\", \"\"]]\n", 340 | " \n", 341 | " for i in range(3):\n", 342 | " for j in range(3):\n", 343 | " button = tk.Button(self.window, height=5, width=10, font=(\"Helvetica\", 32), command=lambda row=i, col=j: self.play(row, col))\n", 344 | " button.grid(row=i, column=j)\n", 345 | " \n", 346 | " self.player_label = tk.Label(self.window, text=\"Player \" + self.current_player + \"'s turn\", font=(\"Helvetica\", 16))\n", 347 | " self.player_label.grid(row=3, column=0, columnspan=3)\n", 348 | " \n", 349 | " self.window.mainloop()\n", 350 | " \n", 351 | " def play(self, row, col):\n", 352 | " if self.board[row][col] == \"\":\n", 353 | " self.board[row][col] = self.current_player\n", 354 | " self.update_board()\n", 355 | " self.check_win()\n", 356 | " self.current_player = \"O\" if self.current_player == \"X\" else \"X\"\n", 357 | " self.player_label.configure(text=\"Player \" + self.current_player + \"'s turn\")\n", 358 | "\n", 359 | " def update_board(self):\n", 360 | " for i in range(3):\n", 361 | " for j in range(3):\n", 362 | " button_text = self.board[i][j] if self.board[i][j] != \"\" else \" \"\n", 363 | " button = self.window.grid_slaves(row=i, column=j)[0]\n", 364 | " button.configure(text=button_text)\n", 365 | "\n", 366 | " def check_win(self):\n", 367 | " winner = \"\"\n", 368 | " for i in range(3):\n", 369 | " if self.board[i][0] == self.board[i][1] == self.board[i][2] != \"\":\n", 370 | " winner = self.board[i][0]\n", 371 | " if self.board[0][i] == self.board[1][i] == self.board[2][i] != \"\":\n", 372 | " winner = self.board[0][i]\n", 373 | " \n", 374 | " if self.board[0][0] == self.board[1][1] == self.board[2][2] != \"\":\n", 375 | " winner = self.board[0][0]\n", 376 | " if self.board[0][2] == self.board[1][1] == self.board[2][0] != \"\":\n", 377 | " winner = self.board[0][2]\n", 378 | "\n", 379 | " if winner:\n", 380 | " self.player_label.configure(text=\"Congratulations! Player \" + winner + \" wins!\")\n", 381 | " for i in range(3):\n", 382 | " for j in range(3):\n", 383 | " button = self.window.grid_slaves(row=i, column=j)[0]\n", 384 | " button.configure(state=\"disabled\")\n", 385 | "\n", 386 | "# Run this script on your Python environment to see the game window open up:\n", 387 | "\n", 388 | "gui = TicTacToeGUI()" 389 | ] 390 | } 391 | ], 392 | "metadata": { 393 | "kernelspec": { 394 | "display_name": "Python 3 (ipykernel)", 395 | "language": "python", 396 | "name": "python3" 397 | }, 398 | "language_info": { 399 | "codemirror_mode": { 400 | "name": "ipython", 401 | "version": 3 402 | }, 403 | "file_extension": ".py", 404 | "mimetype": "text/x-python", 405 | "name": "python", 406 | "nbconvert_exporter": "python", 407 | "pygments_lexer": "ipython3", 408 | "version": "3.9.13" 409 | } 410 | }, 411 | "nbformat": 4, 412 | "nbformat_minor": 5 413 | } 414 | --------------------------------------------------------------------------------