Why is my pygame.MOUSEBUTTONDOWN not working? - python

I'm creating a class for pygame which will allow users to create textboxes for their game. My code doesn't reach the mousebuttondown part for some reason though. I'm attaching my whole code along with parts that I'm facing issues with.
it doesn't print done
def main(self, events, mousepos, id):
for event in events:
if event.type == pygame.QUIT:
exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if self.rect(id, mousepos):
print("done")
keeps printing no
def rect(self, text_id, mousepos):
x, y, width, height = self.dict_all[text_id]
if ((x + width) > mousepos[0] > x) and ((y + height) > mousepos[1] > y):
print("yes")
return True
else:
print("no")
return False
whole code below, update was a method I was trying to make but didn't work for some reason.
import pygame
pygame.font.init()
class textBox:
def __init__(self, surface, id, color, width, height, x, y, antialias, maxtextlen):
self.surface = surface
self.id = id
self.color = color
self.width = width
self.height = height
self.x = x
self.y = y
self.antialias = antialias
self.maxtextlen = maxtextlen
self.text_list = []
self.text_list_keys = []
self.currentId = 0
self.click_check = False
self.font = pygame.font.SysFont('comicsans', 20)
self.dict_all = {}
pygame.draw.rect(self.surface, (self.color), (self.x, self.y, self.width, self.height))
# for i in self.text_list_keys:
# if self.id not in i:
# self.text_list_keys.append(self.id)
# self.text_list.append(tuple(self.id))
# else:
# self.nothing()
self.dict_all[self.id] = tuple((self.x, self.y, self.width, self.height))
def update(self, events, mousepos):
for event in events:
if event.type == pygame.QUIT:
exit()
if event.type == pygame.MOUSEBUTTONDOWN and ((self.x + self.width) > mousepos[0] > self.x) \
and ((self.y + self.height) > mousepos[1] > self.y):
print("reached: " + mousepos)
self.click_check = True
else:
self.click_check = False
if self.click_check:
print("1")
if event.type == pygame.KEYDOWN:
print("#")
if event.key == pygame.K_a:
print("reached")
new_t = ""
for j in range(len(self.text_list)):
t = (self.text_list[j][0]).index(self.getId(self.currentId))
new_t = t
self.text_list[new_t].append("a")
self.surface.blit(self.font.render(f'{self.text_list[new_t]}', self.antialias, (0, 0, 0)),
(self.x, self.y))
else:
print("this")
else:
pass
def rect(self, text_id, mousepos):
x, y, width, height = self.dict_all[text_id]
if ((x + width) > mousepos[0] > x) and ((y + height) > mousepos[1] > y):
print("yes")
return True
else:
print("no")
return False
def getId(self, text_id):
self.currentId = text_id
def nothing(self):
return False
def main(self, events, mousepos, id):
for event in events:
if event.type == pygame.QUIT:
exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if self.rect(id, mousepos):
print("done")
test.py
import pygame
from pygame_textbox import textBox
pygame.init()
win_width = 500
win_height = 500
screen = pygame.display.set_mode((win_width, win_height))
pygame.display.set_caption("test")
run = True
while run:
mouse = pygame.mouse.get_pressed()
screen.fill((0, 0, 0))
events = pygame.event.get()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.quit()
exit()
a = textBox(screen, 1, (255, 255, 255), 100, 30, 100, 100, True, 20)
# a.getId(1)
a.rect(1, mouse)
a.main(events, mouse, 1)
pygame.display.update()

The 2nd argument to the method main has to be the mouse position rather than the mouse buttons:
run = True
while run:
# [...]
mouse_pos = pygame.mouse.get_pos()
a.main(events, mouse_pos, 1)
# [...]
While pygame.mouse.get_pressed() a sequence of booleans representing the state of all the mouse buttons, pygame.mouse.get_pos() returns the X and Y position of the mouse cursor.

Related

My pygame slider moves back to the default position when mouse click is released rather than staying where it was left

When I click on my slider object, I can move the slider around in the given boundaries of the box as expected however when I let go of my mouse button, the blue slider teleports to the left side of the box.
How can I get it so the slider is left when I release the mouse button?
import pygame
pygame.init()
WIDTH = 1820
HEIGHT = 960
res = (WIDTH, HEIGHT)
screen = pygame.display.set_mode(res)
clock = pygame.time.Clock()
WHITE = [255, 255, 255]
GRAY = [125, 125, 125]
BLACK = [0, 0, 0]
BLUE = [0, 0, 155]
class ui(pygame.sprite.Sprite):
def __init__(self, x, y, width, height, colour, name):
self.x = x
self.y = y
self.w = width
self.h = height
self.c = colour
self.n = name
self.font = pygame.font.SysFont("Arial",25)
class slider(ui):
def __init__(self, x, y,width,height):
super().__init__(x,y,width,height,GRAY,"null")
def draw(self):
pygame.draw.rect(screen, GRAY, (self.x, self.y, self.w, self.h)) #Bounding box of slider
def click(self, event):
bound = False
button = pygame.mouse.get_pressed()
x, y = pygame.mouse.get_pos()
if x >= self.x and x <= self.x + self.w:
if y >= self.y and y <= self.y + self.h:
bound = True
else:
bound = False
if bound == True:
if button[0] != 0:
self.x = x
if event.type == pygame.MOUSEBUTTONUP:
self.x = x
pygame.draw.rect(screen, BLUE, (self.x, self.y, 10, self.h)) #actual clickable slider itself
def main():
done = False
while not done:
event_list = pygame.event.get()
for event in event_list:
if event.type == pygame.QUIT:
done = True
screen.fill((255,255,255))
slider1 = slider(250,250,300,100)
slider1.draw()
slider1.click(event)
pygame.display.flip()
clock.tick(60)
main()
I've tried writing some detection for when the user lets go of the mouse button.
if event.type == pygame.MOUSEBUTTONUP:
self.x = x
That works once I let go of the mouse button but then teleports once I move my mouse off the slider or input any key.
You actually have two mistakes in your code:
The slider is deleted and created again each frame.
You don't move the bar on the slider but instead the whole slider itself.
To fix this only create slider1 once and have a variable that traces the position:
...
class slider(ui):
def __init__(self, x, y,width,height):
super().__init__(x,y,width,height,GRAY,"null")
self.pos = x
def draw(self):
pygame.draw.rect(screen, GRAY, (self.x, self.y, self.w, self.h)) #Bounding box of slider
def click(self, event):
bound = False
button = pygame.mouse.get_pressed()
x, y = pygame.mouse.get_pos()
if x >= self.x and x <= self.x + self.w:
if y >= self.y and y <= self.y + self.h:
bound = True
else:
bound = False
if bound == True:
if button[0] != 0:
self.pos = x # (changed to pos)
if event.type == pygame.MOUSEBUTTONUP:
self.pos = x
pygame.draw.rect(screen, BLUE, (self.pos, self.y, 10, self.h)) #actual clickable slider itself
def main():
done = False
slider1 = slider(250,250,300,100) # add
while not done:
event_list = pygame.event.get()
for event in event_list:
if event.type == pygame.QUIT:
done = True
screen.fill((255,255,255))
#slider1 = slider(250,250,300,100) (remove)
slider1.draw()
slider1.click(event)
pygame.display.flip()
clock.tick(60)
pygame.quit()
main()
Now you have a slider. But to make the movement more intuitively you might only move the slider when the mouse button started to be pressed on the slider:
...
class slider(ui):
def __init__(self, x, y, width, height):
super().__init__(x, y, width, height, GRAY, "null")
self.pos = x
self.pressed = False
self.bound = False
def draw(self):
pygame.draw.rect(screen, GRAY, (self.x, self.y, self.w, self.h)) # Bounding box of slider
def click(self):
button = pygame.mouse.get_pressed()
x, y = pygame.mouse.get_pos()
if x >= self.x and x <= self.x + self.w and y >= self.y and y <= self.y + self.h:
if True in button and not self.pressed:
self.bound = True
if not True in button:
self.bound = False
if self.bound:
self.pos = max(self.x, min(self.x + self.w, x))
pygame.draw.rect(screen, BLUE, (self.pos, self.y, 10, self.h)) # actual clickable slider itself
self.pressed = True in button
def main():
done = False
slider1 = slider(250, 250, 300, 100)
while not done:
event_list = pygame.event.get()
for event in event_list:
if event.type == pygame.QUIT:
done = True
screen.fill((255, 255, 255))
slider1.draw()
slider1.click()
pygame.display.flip()
clock.tick(60)
pygame.quit()
main()

Pygame slider is not moving on the place I pressed [duplicate]

I want to be able to drag the blue object along the x-axis (black line) using mouse so that it does not move in y-direction. When I try to drag it, nothing happens. Where is the problem?
import pygame
def initialize():
pygame.init()
global height, width
height = 600
width = 900
screen = pygame.display.set_mode((width, height))
screen.fill((255, 255, 255))
pygame.draw.line(screen, (0, 0 ,0), (0, height / 2), (width, height / 2), 3)
return screen
def object():
dragging = False
object_1 = pygame.rect.Rect(width / 4, height / 2 - 75, 50, 150)
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
if object_1.collidepoint(event.pos):
dragging = True
mouse_x, mouse_y = event.pos
offset_x = object_1.x - mouse_x
elif event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
dragging = False
elif event.type == pygame.MOUSEMOTION:
if dragging:
mouse_x, mouse_y = event.pos
object_1.x = mouse_x + offset_x
return object_1
if __name__ == "__main__":
running = True
screen = initialize()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
object_1 = object()
pygame.draw.rect(screen, (0, 0, 250), object_1)
pygame.display.update()
You have to create the object once before the main application loop and you have to handle the events in the application loop.
Furthermore you have to redraw the entire scene in the application loop. The main application loop has to:
handle the events by either pygame.event.pump() or pygame.event.get().
update the game states and positions of objects dependent on the input events and time (respectively frames)
clear the entire display or draw the background
draw the entire scene (blit all the objects)
update the display by either pygame.display.update() or pygame.display.flip()
Add a function which creates an object:
def create_object():
object_1 = pygame.rect.Rect(width / 4, height / 2 - 75, 50, 150)
return object_1
Create an object before the application loop:
if __name__ == "__main__":
# [...]
object_1 = create_object()
while running:
# [...]
Add a function which can drag an object:
dragging = False
def drag_object(events, object_1):
global dragging, offset_x
for event in events:
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
if object_1.collidepoint(event.pos):
dragging = True
mouse_x, mouse_y = event.pos
offset_x = object_1.x - mouse_x
elif event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
dragging = False
elif event.type == pygame.MOUSEMOTION:
if dragging:
mouse_x, mouse_y = event.pos
object_1.x = mouse_x + offset_x
Get the list of events once in the application loop and pass the events to the function drag_object:
while running:
# [...]
drag_object(events, object_1)
Clear the display, draw the scene and update the display in the application loop:
while running:
# [...]
screen.fill((255, 255, 255))
pygame.draw.line(screen, (0, 0 ,0), (0, height / 2), (width, height / 2), 3)
pygame.draw.rect(screen, (0, 0, 250), object_1)
pygame.display.update()
See the example:
import pygame
def initialize():
pygame.init()
global height, width
height = 600
width = 900
screen = pygame.display.set_mode((width, height))
return screen
def create_object():
object_1 = pygame.rect.Rect(width / 4, height / 2 - 75, 50, 150)
return object_1
dragging = False
def drag_object(events, object_1):
global dragging, offset_x
for event in events:
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
if object_1.collidepoint(event.pos):
dragging = True
mouse_x, mouse_y = event.pos
offset_x = object_1.x - mouse_x
elif event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
dragging = False
elif event.type == pygame.MOUSEMOTION:
if dragging:
mouse_x, mouse_y = event.pos
object_1.x = mouse_x + offset_x
if __name__ == "__main__":
running = True
screen = initialize()
object_1 = create_object()
while running:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
running = False
drag_object(events, object_1)
screen.fill((255, 255, 255))
pygame.draw.line(screen, (0, 0 ,0), (0, height / 2), (width, height / 2), 3)
pygame.draw.rect(screen, (0, 0, 250), object_1)
pygame.display.update()
Alternatively you can create a class for the object:
import pygame
def initialize():
pygame.init()
global height, width
height = 600
width = 900
screen = pygame.display.set_mode((width, height))
return screen
class MyObject:
def __init__(self):
self.rect = pygame.rect.Rect(width / 4, height / 2 - 75, 50, 150)
self.dragging = False
self.offset_x = 0
def drag(self, events):
for event in events:
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
if self.rect.collidepoint(event.pos):
self.dragging = True
self.offset_x = self.rect.x - event.pos[0]
elif event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
self.dragging = False
elif event.type == pygame.MOUSEMOTION:
if self.dragging:
self.rect.x = event.pos[0] + self.offset_x
def draw(self, surf):
pygame.draw.rect(surf, (0, 0, 250), object_1)
if __name__ == "__main__":
running = True
screen = initialize()
object_1 = MyObject()
while running:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
running = False
object_1.drag(events)
screen.fill((255, 255, 255))
pygame.draw.line(screen, (0, 0 ,0), (0, height / 2), (width, height / 2), 3)
object_1.draw(screen)
pygame.display.update()

Error with transitioning from main menu to game pygame

Uhh sorry for the super vague title, I have no idea whats wrong with my code either.
if event.type == pygame.K_SPACE:
run= True
There appears to be a problem when running this line, like the code is shaded a different colour on my screen, and it doesn't change run to True
This problem seems to be fixed if i delete:
def mainmenu()
and just use a while loop, however, I think it gets pretty messy and am quite hesitant to delete that.
Furthermore, when I run the mainmenu() function, it takes quite a long time to load up, a problem which I haven't had thus far and I am unsure why or how to fix it.
import pygame
import time
import random
pygame.init()
window = pygame.display.set_mode((1000,700))
White=(255,255,255)
font = pygame.font.SysFont("comicsansms", 25)
#for easier counting of lives, score here starts from 1, just simply subtract 1 from whats displayed later
score = 1
clicks = 1
lives = 3
run=False
intro=True
def mainmenu():
while intro:
window.fill((0, 0, 0))
text = font.render("Press space to start!" , True, White)
window.blit(text, (500, 350))
for event in pygame.event.get():
if event.type == pygame.QUIT:
intro = False
pygame.quit()
quit()
if event.type == pygame.K_SPACE:
run= True
class Circle():
def __init__(self, color, x, y, radius, width):
self.color = color
self.x = x
self.y = y
self.radius = radius
self.width = width
def draw(self, win, outline=None):
pygame.draw.circle(win, self.color, (self.x, self.y), self.radius, self.width)
def isOver(self, mouse):
dx, dy = mouse[0] - self.x, mouse[1] - self.y
return (dx * dx + dy * dy) <= self.radius * self.radius
circles = []
def redrawWindow():
window.fill((0, 0, 0))
for c in circles:
c.draw(window)
text = font.render("Score:" + str(score-1), True, White)
window.blit(text, (0,0))
text = font.render("Lives:" + str(lives), True, White)
window.blit(text, (900, 0))
clock = pygame.time.Clock()
FPS = 60
x = str(pygame.time.get_ticks())
current_time = 0
next_circle_time = 0
while run:
delta_ms = clock.tick()
current_time += delta_ms
if current_time > next_circle_time:
next_circle_time = current_time + 1000 # 1000 milliseconds (1 second)
r = 20
new_circle = Circle((255, 255, 255), random.randint(r, 800-r), random.randint(r, 600-r), r, r)
circles.append(new_circle)
print()
redrawWindow()
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run=False
pygame.quit()
quit()
if event.type == pygame.MOUSEBUTTONDOWN:
clicks += 1
mouse = pygame.mouse.get_pos()
for circle in circles:
if circle.isOver(mouse):
score += 1
circles.pop(circles.index(circle))
lives= 3-(clicks-score)
pygame.display.update()
run is a variable in global namespace. If you want to write a variable in global namespace within a function, then you have to use the global statement, which means that the listed identifiers are to be interpreted as globals:
run=False
intro=True
def mainmenu():
global run, intro
while intro:
window.fill((0, 0, 0))
text = font.render("Press space to start!" , True, White)
window.blit(text, (500, 350))
for event in pygame.event.get():
if event.type == pygame.QUIT:
intro = False
pygame.quit()
quit()
if event.type == pygame.K_SPACE:
run = True

How to fix a not working Space key in python?

Can any one see what I did wrong, please? I want the block to jump but it doesnt work properly. This is my first python project so please try to explain what I did wrong so I dont do it again, thanks.
import pygame
pygame.init()
bg = pygame.image.load('bg.jpg')
class Player():
def __init__(self, x, y, height, width):
self.x = x
self.y = y
self.height = height
self.width = width
self.Jumpcount = 10
self.Isjump = False
def draw(self, window):
pygame.draw.rect(window, (255, 0, 0), (self.x, self.y, self.width, self.height))
pygame.draw.rect(window, (0, 255, 0), (self.x, self.y, self.width / 2, self.height / 2))
pygame.draw.rect(window, (0, 255, 0), (self.x + self.width / 2, self.y + self.height / 2, self.width / 2, self.height / 2))
pygame.draw.rect(window, (139, 26, 26), (0, 400 + self.height, 500, 500 - self.height))
def Jump(self, Jumping):
if Jumping:
self.Isjump = True
if self.Isjump:
if self.Jumpcount >= -10:
neg = 1
if self.Jumpcount < 0:
neg = -1
self. y = self.Jumpcount**2 * 0.25 * neg
self.Jumpcount -= 1
else:
self.Isjump = False
self.Jumpcount = 10
win = pygame.display.set_mode((500, 500))
pygame.display.set_caption('Test')
Jumping = False
run = True
man = Player(70, 400, 40, 40)
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
print('123')
Jumping = True
man.Jump(Jumping)
win.blit(bg, (0, 0))
man.draw(win)
pygame.display.update()
pygame.quit()
There is no error message but when I press space it doesnt do anything.
Remove the second pygame.event.get() loop. The first loop is consuming all the events, but checks only the QUIT event and does nothing for other events. The second loop is likely empty. Do all the event checks in the first loop.
You want to have only one event loop each iteration of the main loop.
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
print('123')
Jumping = True
man.Jump(Jumping)
I think your problem lies in having two for loops event in pygame.event.get()
To fix this you just want to have the two if statements under one for loop like so:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
print('123')
Jumping = True
man.Jump(Jumping)
that should fix your problem.

Python flask game not initializing

I have my flask file and a seperate file which contains a pygame. Both work seperately, How would i combine the flask so that when i press my link on my webpage it starts running the external file, how would I call it?
from flask import Flask, render_template
import going
app = Flask(__name__)
#app.route('/')
def index():
return render_template('index.html')
#app.route('/my-link/')
def my_link():
return going.main()
if __name__ == '__main__':
app.run(debug=True)
At the moment I am trying to run the main() method to initialize the program.
import pygame
##1100 * 800
size = [1100, 800]
score1 = 0
score2 = 0
blue = (100, 149, 237)
black = (0, 0, 0)
brown = (165,42,42)
white = (255, 255, 255)
green =(0,100,0)
red = (255,0,0)
dark_red = (200,0,0)
grey = (100,100,100)
other_grey = (0,0,100)
background = 'Mahogany.jpg'
pass_count = 0
player = 1
clock = pygame.time.Clock()
class Player(object):
def ___init__(self,id):
self.id = 1
def quitGame(self):
pygame.quit()
quit()
def pass_turn(self):
global pass_count
pass_count += 1
if pass_count == 2:
quitGame()
def score(player_text, score):
return player_text + str(score)
class Stone(object):
def __init__(self,board,position,color):
self.board = board
self.position = position
self.color = color
self.placeStone()
def placeStone(self):
coords = (self.position[0] * 50, self.position[1] * 50)
pygame.draw.circle(self.board,self.color,coords,20,0)
pygame.display.update()
class Board(object):
def draw_board(self):
for i in range(12):
for j in range(12):
rect = pygame.Rect(55 + (50 * i), 100 + (50 * j), 50, 50)
pygame.draw.rect(background, blue, rect, 1)
screen.blit(background, (0,0))
pygame.display.update()
def text_objects(self,text, font):
textSurface = font.render(text, True, black)
return textSurface, textSurface.get_rect()
def button(self,msg,x,y,w,h,ic,ac,action = None):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
if x+w > mouse[0] > x and y+h > mouse[1] > y:
pygame.draw.rect(screen, ac,(x,y,w,h))
if click[0] == 1 and action != None:
action()
else:
pygame.draw.rect(screen, ic,(x,y,w,h))
smallText = pygame.font.Font("freesansbold.ttf",20)
textSurf, textRect = self.text_objects(msg, smallText)
textRect.center = ( (x+(w/2)), (y+(h/2)) )
screen.blit(textSurf, textRect)
def game_intro(self):
intro = True
while intro:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
screen.blit(background, (0,0))
largeText = pygame.font.SysFont("comicsansms",60)
TextSurf, TextRect = self.text_objects("GONLINE", largeText)
TextRect.center = ((1100/2),(800/2))
screen.blit(TextSurf, TextRect)
self.button("Play!",200,500,100,100,grey,other_grey,self.play_game)
self.button("Quit!",700,500,100,100,red,dark_red,Player.quitGame)
pygame.display.update()
clock.tick(15)
def play_game(self):
width = 20
height = 20
space_between = 5
global player
finish = False
self.draw_board()
while not finish:
for event in pygame.event.get():
if event.type == pygame.QUIT:
finish = True
elif event.type == pygame.MOUSEBUTTONDOWN and player == 1:
position = pygame.mouse.get_pos()
if (event.button == 1) and (position[0] > 55 and position[0] < 710) and (position[1] > 100 and position[1] < 750):
x = int(round(((position[0]) / 50.0), 0))
y = int(round(((position[1]) / 50.0), 0))
Stone(screen,(x,y),white)
player = 2
elif event.type == pygame.MOUSEBUTTONDOWN and player == 2:
position = pygame.mouse.get_pos()
if (event.button == 1) and(position[0] > 55 and position[0] < 710) and (position[1] > 100 and position[1] < 750):
x = int(round(((position[0]) / 50.0), 0))
y = int(round(((position[1] ) / 50.0), 0))
Stone(screen,(x,y),black)
player = 1
clock.tick(60)
self.button("Pass!",750,200,100,100,grey,other_grey,Player.pass_turn)
self.button("Quit!",950,200,100,100,red,dark_red,Player.quitGame)
self.button(score("Player 1: ", score1),750,400,300,110,white,white)
self.button(score("Player 2: ",score2),750,600,300,110,white, white)
pygame.display.update()
pygame.quit()
def main():
player = Player()
board = Board()
board.game_intro()
if __name__ == "__main__":
pygame.init()
screen = pygame.display.set_mode(size, 0, 32)
pygame.display.set_caption("Go_Online")
background = pygame.image.load(background).convert()
main()
Here is the main game file
It seems that the two ways you try to call your game are slightly different.
The successful way, which seems to be something like
$ python going.py
runs this code
if __name__ == "__main__":
pygame.init()
screen = pygame.display.set_mode(size, 0, 32)
pygame.display.set_caption("Go_Online")
background = pygame.image.load(background).convert()
main()
The flask route, when triggered runs this
return going.main()
You're missing some setup. My guess is that the bottom of your going.py should look like this.
def main():
pygame.init()
screen = pygame.display.set_mode(size, 0, 32)
pygame.display.set_caption("Go_Online")
background = pygame.image.load(background).convert()
player = Player()
board = Board()
board.game_intro()
if __name__ == '__main__':
main()

Categories

Resources