High Definition Standard Definition Theater
Video id : xg4Zou773jo
ImmersiveAmbientModecolor: #c2c2bd (color 2)
Video Format : (720p) openh264 ( https://github.com/cisco/openh264) mp4a.40.2 | 44100Hz
Audio Format: 140 ( High )
PokeEncryptID: 8ebe59f5dc9f079b1899db16119af966984f651e9c5dc500c5bc8545cc880b5357c2a523a70b7b19495b10205220308e
Proxy : cal1.iv.ggtyler.dev - refresh the page to change the proxy location
Date : 1734533658701 - unknown on Apple WebKit
Mystery text : eGc0Wm91Nzczam8gaSAgbG92ICB1IGNhbDEuaXYuZ2d0eWxlci5kZXY=
143 : true
221 Views тАв Sep 5, 2023 тАв Click to toggle off description
import tkinter as tk
from tkinter import messagebox

Create the main window
root = tk.Tk()
root.title("Tic-Tac-Toe")

Initialize variables
current_player = "X"
board = [" " for _ in range(9)]

Function to handle a button click
def on_click(button):
global current_player
index = int(button["text"]) - 1

if board[index] == " ":
board[index] = current_player
button["text"] = current_player
if check_winner(current_player):
messagebox.showinfo("Tic-Tac-Toe", f"Player {current_player} wins!")
reset_game()
elif " " not in board:
messagebox.showinfo("Tic-Tac-Toe", "It's a tie!")
reset_game()
else:
current_player = "O" if current_player == "X" else "X"

Function to check for a win
def check_winner(player):
winning_combinations = [(0, 1, 2), (3, 4, 5), (6, 7, 8),
(0, 3, 6), (1, 4, 7), (2, 5, 8),
(0, 4, 8), (2, 4, 6)]

for combo in winning_combinations:
if board[combo[0]] == board[combo[1]] == board[combo[2]] == player:
return True
return False

Function to reset the game
def reset_game():
global current_player, board
current_player = "X"
board = [" " for _ in range(9)]
for button in buttons:
button["text"] = " "

Create buttons for the Tic-Tac-Toe grid
buttons = [tk.Button(root, text=str(i + 1), font=("Helvetica", 24), width=3, height=1, command=lambda i=i: on_click(buttons[i]))
for i in range(9)]


Arrange buttons in a 3x3 grid
for i, button in enumerate(buttons):
row = i // 3
col = i % 3
button.grid(row=row, column=col)

Create a "Restart" button
restart_button = tk.Button(root, text="Restart", font=("Helvetica", 14), width=10, height=1, command=reset_game)
restart_button.grid(row=3, column=1)

Start the GUI main loop
root.mainloop()
Metadata And Engagement

Views : 221
Genre: People & Blogs
License: Standard YouTube License
Uploaded At Sep 5, 2023 ^^


warning: returnyoutubedislikes may not be accurate, this is just an estiment ehe :3
Rating : 5 (0/7 LTDR)

100.00% of the users lieked the video!!
0.00% of the users dislieked the video!!
User score: 100.00- Masterpiece Video

RYD date created : 2024-02-09T10:59:09.57853Z
See in json
Connections
Nyo connections found on the description ;_; report an issue lol

1 Comments

Top Comments of this video!! :3

@UP14_Programmer

1 year ago

import tkinter as tk
from tkinter import messagebox

# Create the main window
root = tk.Tk()
root.title("Tic-Tac-Toe")

# Initialize variables
current_player = "X"
board = [" " for _ in range(9)]

# Function to handle a button click
def on_click(button):
global current_player
index = int(button["text"]) - 1

if board[index] == " ":
board[index] = current_player
button["text"] = current_player
if check_winner(current_player):
messagebox.showinfo("Tic-Tac-Toe", f"Player {current_player} wins!")
reset_game()
elif " " not in board:
messagebox.showinfo("Tic-Tac-Toe", "It's a tie!")
reset_game()
else:
current_player = "O" if current_player == "X" else "X"

# Function to check for a win
def check_winner(player):
winning_combinations = [(0, 1, 2), (3, 4, 5), (6, 7, 8),
(0, 3, 6), (1, 4, 7), (2, 5, 8),
(0, 4, 8), (2, 4, 6)]

for combo in winning_combinations:
if board[combo[0]] == board[combo[1]] == board[combo[2]] == player:
return True
return False

# Function to reset the game
def reset_game():
global current_player, board
current_player = "X"
board = [" " for _ in range(9)]
for button in buttons:
button["text"] = " "

# Create buttons for the Tic-Tac-Toe grid
buttons = [tk.Button(root, text=str(i + 1), font=("Helvetica", 24), width=3, height=1, command=lambda i=i: on_click(buttons[i]))
for i in range(9)]


# Arrange buttons in a 3x3 grid
for i, button in enumerate(buttons):
row = i // 3
col = i % 3
button.grid(row=row, column=col)

# Create a "Restart" button
restart_button = tk.Button(root, text="Restart", font=("Helvetica", 14), width=10, height=1, command=reset_game)
restart_button.grid(row=3, column=1)

# Start the GUI main loop
root.mainloop()

|

Go To Top