Reputation: 21
I'm a beginner trying to code a Tic Tac Toe program (using Python in VSC) with this video tutorial: https://www.youtube.com/watch?v=yniQ15A7MLk. But when I try to make the circle show up when clicked, the program closes down when I click on the screen and the terminal prints this error message:
TypeError: function missing required argument 'radius' (pos 4)
I don't think it's the clicking function, since I get the results printed in text in the VSC terminal. But it doesn't show up in the program window. And I don't think it's something in the draw function, since I tried with an image instead and the same thing happened (program closing down when I clicked on the screen).
import pygame
import numpy
pygame.init()
white = (255, 255, 255)
black = (0, 0, 0)
red = (255, 0, 0)
height = 700
width = 700
line_thickness = 20
display = pygame.display.set_mode((height, width))
display.fill(black)
board = numpy.zeros((3, 3))
def lines():
pygame.draw.line(display, white, (50, 250), (650, 250), line_thickness)
pygame.draw.line(display, white, (50, 450), (650, 450), line_thickness)
pygame.draw.line(display, white, (250, 50), (250, 650), line_thickness)
pygame.draw.line(display, white, (450, 50), (450, 650), line_thickness)
lines()
square_size = 200
o_radius = 60
o_width = 15
def draw_figures():
for row in range(3):
for col in range(3):
if board[row, col] == 1:
pygame.draw.circle(display, red, ((int(row * square_size + square_size // 2), int(col * square_size + square_size // 2)), o_radius, o_width))
def marked_square(row, col, player):
board[row, col] = player
def available_square(row, col):
return board[row, col] == 0
player = 1
pygame.display.update()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_x = event.pos[0]
mouse_y = event.pos[1]
clicked_row = int(mouse_y // 200)
clicked_col = int(mouse_x // 200)
if available_square(clicked_row, clicked_col):
if player == 1:
marked_square(clicked_row, clicked_row, 1)
player = 2
elif player == 2:
marked_square(clicked_row, clicked_row, 2)
player = 1
draw_figures()
print(board)
Upvotes: 2
Views: 78
Reputation: 4241
in:
pygame.draw.circle(display, red, ((int(row * square_size + square_size // 2), int(col * square_size + square_size // 2)), o_radius, o_width))
Your brackets are incorrect, so you only have 3 parameters
pygame.draw.circle(
display,
red,
((int(row * square_size + square_size // 2), int(col * square_size + square_size // 2)), o_radius, o_width)
)
I assume you mean
pygame.draw.circle(display, red, (int(row * square_size + square_size // 2), int(col * square_size + square_size // 2)), o_radius, o_width)
It would probably be cleaner to have some helper variables
x = int(row * square_size + square_size // 2)
y = int(col * square_size + square_size // 2)
pygame.draw.circle(display, red, (x, y), o_radius, o_width)
Upvotes: 2