Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
import contextlib
with contextlib.redirect_stdout(None):
import pygame
import os
import time
# Define some colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
BLUE = (0,0,255)
z = 0
b = 0
h= 0
pygame.init()
image = []
path = 'E:\Andrew Photos'
pub= open("public.txt","w+")
now = open("nowhere.txt","w+")
sch = open("school.txt","w+")
files = []
for r, d, f in os.walk(path):
for file in f:
if '.jpg' in file:
files.append(os.path.join(r, file))
print (file)
public = []
school = []
nowhere = []
# Set the width and height of the screen [width, height]
size = (700, 500)
screen = pygame.display.set_mode((0,0),pygame.FULLSCREEN)
x, y = screen.get_size()
pygame.display.set_caption("Testy Testerson")
# Loop until the user clicks the close button.
done = False
i =0
# Used to manage how fast the screen updates
clock = pygame.time.Clock()
click = 0
# -------- Main Program Loop -----------
while not done:
x, y = screen.get_size()
while i < len(files):
mousex, mousey = pygame.mouse.get_pos()
# --- Main event loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
# if any mouse button is pressed pygame.MOUSEBUTTONUP
if event.type == pygame.MOUSEBUTTONUP:
click = 0
if event.type == pygame.MOUSEBUTTONDOWN:
# if the left button is pressed
if event.button == 1:
if mousex >= x-50:
if mousey <= 30:
exit(1)
pygame.quit()
done = True
if mousex >= x-300:
if mousey >= y-100:
nowhere.append(files[i])
now.write(files[i])
i = i +1
elif mousex <= 300:
if mousey >=y-100:
pub.write(files[i])
i = i+1
public.append(files[i-1])
elif mousex <=800:
if mousex >= 1100:
if mousey >= y-100:
school.append(files[i])
sch.write(files[i])
i = 1 +1
click = 1
if i == len(files):
pygame.QUIT()
# --- Game logic should go here
# --- Screen-clearing code goes here
# Here, we clear the screen to white. Don't put other drawing commands
# above this, or they will be erased with this command.
# If you want a background image, replace this clear with blit'ing the
# background image.
screen.fill(WHITE)
if i >= len(files):
pygame.QUIT
#pygame.draw.rect(screen, RED,(x-50,0,50,30))
if i < len(files):
image = pygame.image.load(files[i])
screen.blit(image, (0,0))
pygame.draw.rect(screen, RED,(x-300,y-100,300,100))
pygame.draw.rect(screen, GREEN,(0,y-100,300,100))
pygame.draw.rect(screen, BLUE,(800,y-100,300,100))
# --- Drawing code should go here
# i = 0
# while i < len(files):
# image = pygame.image.load(files[i])
# screen.blit(image, (0,0))
# pygame.draw.rect(screen, RED,(x-300,y-100,300,100))
# pygame.display.flip()
# if mousex >= x-300:
# if mousey >= y-100:
# if click == 1:
# nowhere.append(files[i])
# time.sleep(1)
# if click == 0:
# i = i+1
# --- Go ahead and update the screen with what we've drawn.
pygame.display.flip()
# --- Limit to 60 frames per second
# Close the window and quit.
clock.tick(60)
pygame.QUIT()
exit()
I am trying to make it so when you click the squares at the bottom, it adds to three separate text files the name of the file that went to each box, but im having some issues, and ive been able to figure out most of them, but cant fix them.
The first click does not work.
The blue rectangle does not function, at all
Nothing ends up in the files at all. I would settle for all of them in the same file with a header and a gap between lists.
Currently i am using 4 random JPG.s to do this, but the goal is to make it so i can sort 2,000 of them.
Alright. so i was in windowed mode instead of fullscreen, but i think the problem was a mistake in the if statements, you had a '<' around the wrong way
this works
if mousex >= x-300:
if mousey >= y-100:
print("red")
i = i +1
elif mousex <= 300:
if mousey >=y-100:
print("green")
i += 1
elif mousex >=500:
if mousex <= 800:
if mousey >= y-100: # this was also 1100 which doesnt help
print("blue")
i = 1 +1
i changed the locations of the buttons as they were going off my screen so this is what i had
pygame.draw.rect(screen, RED,(x-300,y-100,300,100))
pygame.draw.rect(screen, GREEN,(0,y-100,300,100))
pygame.draw.rect(screen, BLUE,(500,y-100,300,100))
Related
I learned how to print image in pygame, but I don't know how to make a dynamic position(It can change the image position by itself). What did I miss? Here's my attempt.
import pygame
screen_size = [360,600]
screen = pygame.display.set_mode(screen_size)
background = pygame.image.load("rocketship.png")
keep_alive = True
while keep_alive:
planet_x = 140
o = planet_x
move_direction = 'right'
if move_direction == 'right':
while planet_x == 140 and planet_x < 300:
planet_x = planet_x + 5
if planet_x == 300:
planet_x = planet_x - 5
while planet_x == 0:
if planet_x == 0:
planet_x+=5
screen.blit(background, [planet_x, 950])
pygame.display.update()
You don't need nested loops to animate objects. You have one loop, the application loop. Use it! You need to redraw the entire scene in each frame. Change the position of the object slightly in each frame. Since the object is drawn at a different position in each frame, the object appears to move smoothly.
Define the path the object should move along by a list of points and move the object from one point to another.
Minimal example
import pygame
pygame.init()
window = pygame.display.set_mode((400, 400))
clock = pygame.time.Clock()
corner_points = [(100, 100), (300, 300), (300, 100), (100, 300)]
pos = corner_points[0]
speed = 2
def move(pos, speed, points):
direction = pygame.math.Vector2(points[0]) - pos
if direction.length() <= speed:
pos = points[0]
points.append(points[0])
points.pop(0)
else:
direction.scale_to_length(speed)
new_pos = pygame.math.Vector2(pos) + direction
pos = (new_pos.x, new_pos.y)
return pos
image = pygame.image.load('bird.png').convert_alpha()
run = True
while run:
clock.tick(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pos = move(pos, speed, corner_points)
image_rect = image.get_rect(center = pos)
window.fill(0)
pygame.draw.lines(window, "gray", True, corner_points)
window.blit(image, image_rect)
pygame.display.update()
pygame.quit()
exit()
This question already has answers here:
Not letting the character move out of the window
(2 answers)
Closed 2 years ago.
I'm trying to make the paddles move up and down : 1 rectangle. moving with w/a/s/d keys 2 rectangle. with arrows. I'm having trouble making the paddles stay in the screen?
You will make two “paddles” (i.e. Rectangles), one on the left side and one on the right side of the screen. These rectangles should be taller than they are wide (i.e. Look like a paddle from a pong game). The paddle on the left should be able to move up and down using the w and s keys, the paddle on the right should move up and down using the up and down arrow keys. Both paddles should not be allowed to leave the top or bottom of the screen. (* for this assignment you are just creating the paddles and getting them moving properly,, no balls necessary). Try to avoid hardcoded values.
# import the necessary modules
import pygame
import sys
#initialize pygame
pygame.init()
# set the size for the surface (screen)
screen_h = 800
screen_w = 600
screen = pygame.display.set_mode((screen_h,screen_w),0)
# set the caption for the screen
pygame.display.set_caption("Template")
# define colours you will be using
WHITE = (255,255,255)
GREEN = (0,255,0)
RED = (255,0,0)
BLUE = (0,0,255)
BLACK = (0,0,0)
YELLOW = (255,255,0)
#initialize variables for player
#variables for first rectangle
R1x = 740
R1y = 300
R1w = 50
R1h = 132
R1dx = 0
R1dy = 0
#variables for second rectangle
R2x = 10
R2y = 300
R2w = 50
R2h = 132
R2dx = 0
R2dy = 0
#speed
speed = 3
screen.fill(BLACK)
# set main loop to True so it will run
main = True
# main loop
while main:
for event in pygame.event.get(): # check for any events (i.e key press, mouse click etc.)
if event.type ==pygame.QUIT: # check to see if it was "x" at top right of screen
main = False # set the "main" variable to False to exit while loop
if event.type ==pygame.KEYDOWN:
if event.key == pygame.K_UP:
R1dx = 0
R1dy = -speed
elif event.key == pygame.K_DOWN:
R1dx = 0
R1dy = speed
if event.key == pygame.K_w:
R2dx = 0
R2dy = -speed
elif event.key == pygame.K_s:
R2dx = 0
R2dy = speed
if event.type == pygame.KEYUP:
if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
R1dx = 0
R1dy = 0
elif event.key == pygame.K_w or event.key == pygame.K_s:
R2dx = 0
R2dy = 0
# move the x and y positions of the rectangles
oldR1x = R1x
oldR1y = R1y
R1x = R1x + R1dx
R1y = R1y + R1dy
if R1x >= screen_w-50:
R1x = oldR1x
R1y = oldR1y
if R1x<= 50:
R1x = oldR1x
R1y = oldR1y
if R1y>= screen_h-50:
R1x = oldR1x
R1y = oldR1y
if R1y<= 50:
R1x = oldR1x
R1y = oldR1y
# draw the shapes, in this case the blue rectangles
pygame.draw.rect(screen, WHITE,(R1x, R1y, R1w, R1h),0)
pygame.draw.rect(screen, WHITE,(R2x, R2y, R2w, R2h),0)
# we are using .flip() here, it basically works the same as .update()
# we will discuss this more in class (you can use either one)
pygame.display.flip()
# quit pygame and exit the program (i.e. close everything down)
pygame.quit()
sys.exit()
First of all you have swapped the screen width (screen_w) and the screen height (screen_h). It has to be:
# set the size for the surface (screen)
screen_w = 800
screen_h = 600
screen = pygame.display.set_mode((screen_w,screen_h),0)
The paddles move just up an down, so it sufficient to limit the y coordinate of the pddels to the range [0, screen_h-R1h]. Note, R1y respectively R2y are the top coordinate of the paddles:
R1y = max(0, min(screen_h-R1h, R1y + R1dy))
R2y = max(0, min(screen_h-R2h, R2y + R2dy))
Furthermore, the screen has to be cleared in the main application loop (screen.fill(BLACK)):
while main:
for event in pygame.event.get(): # check for any events (i.e key press, mouse click etc.)
if event.type ==pygame.QUIT: # check to see if it was "x" at top right of screen
main = False # set the "main" variable to False to exit while loop
if event.type ==pygame.KEYDOWN:
# [...]
# move the x and y positions of the rectangles
R1y = max(0, min(screen_h-R1h, R1y + R1dy))
R2y = max(0, min(screen_h-R2h, R2y + R2dy))
# clear screen
screen.fill(BLACK)
# draw the shapes, in this case the blue rectangles
pygame.draw.rect(screen, WHITE,(R1x, R1y, R1w, R1h),0)
pygame.draw.rect(screen, WHITE,(R2x, R2y, R2w, R2h),0)
# we are using .flip() here, it basically works the same as .update()
# we will discuss this more in class (you can use either one)
pygame.display.flip()
Note, it the paddles would move along the x axis too (left, right), then the restriction of the x coordinate is similar:
R1x = max(0, min(screen_w-R1w, R1x + R1dx))
R2x = max(0, min(screen_w-R2w, R2x + R2dx))
I want to click these 2 circle balls and drag them to mouse current mouse position but it is not working.
I just want to click and drag the balls with mouse.
some codes was not added(import pygame,draw a display, colors etc.)
import pygame
window = pygame.display.set_mode((800,400))
clock = pygame.time.Clock()
##bg = pygame.image.load("bgpool.png")
##window.blit(bg,(0,0))
black = (0,0,0)
yellow = (255,255,0)
class Circle:
def __init__(self,x,y,color,radius):
self.x = x
self.y = y
self.color = color
self.radius = radius
pygame.draw.circle(window, color,(x,y),radius)
def quitgame():
pygame.quit()
quit()
def loop():
cikis = False
while not cikis:
for event in pygame.event.get():
if event.type == pygame.QUIT:
cikis = True
pygame.quit()
quit()
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
bas = pygame.MOUSEBUTTONDOWN
window.fill((255,255,255))
main_circle = Circle(75,175,black,10)
aim_circle = Circle(375,175,yellow,10)
if click[0] == 1:
if mouse[0] >= main_circle.x and mouse[0] <= main_circle.x + main_circle.radius:
if mouse[1] >= main_circle.y and mouse[1] <= main_circle.y + main_circle.radius:
if click[0] == 1:
main_circle.x == mouse[0]
main_circle.y == mouse[1]
clock.tick(120)
pygame.display.update()
loop()
pygame.quit()
quit()
While click = pygame.mouse.get_pressed() works, it's very much recommended to use Pygame's events, like you have done for pygame.QUIT.
Because you didn't provide much code, I added the bare minimum to make the code runnable, and I commented every modification:
import pygame
pygame.init()
window = pygame.display.set_mode((700, 500))
class Circle:
def __init__(self, x, y, color, radius):
# Changed pos to contain both coordinates
self.pos = (x, y)
# Where the radius ends
self.x_boundary = (x - radius, x + radius)
self.y_boundary = (y - radius, y + radius)
self.color = color
self.radius = radius
def recalc_boundary(self):
# Recalculate the boundaries of the circle,
# this is needed whenever the circle is moved
self.x_boundary = (
self.pos[0] - self.radius, self.pos[0] + self.radius
)
self.y_boundary = (
self.pos[1] - self.radius, self.pos[1] + self.radius
)
# Single instantiation of our circle
# didn't add aim_circle because it is irrelevant
# in my answer
main_circle = Circle(75, 175, (255, 0, 0), 10)
# Small lambda function that'll take care of
# checking whether or not a point x is
# within two boundaries.
# This replaces your
# `if mouse[0] >= main_circle.x and mouse[0]
# <= main_circle.x + main_circle.radius:`
# lines
within = lambda x, low, high: low <= x <= high
# Boolean that attests to whether or not the
# user is clicking on our circle
selected = False
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
# Test for MOUSEBUTTONDOWN events
elif event.type == pygame.MOUSEBUTTONDOWN:
# Left mouse button
if event.button == 1:
pos = pygame.mouse.get_pos()
# Check if the mouse is within
# our circle's limits, to see if the
# user is trying to click on it
if (
within(pos[0], *main_circle.x_boundary)
and within(pos[1], *main_circle.y_boundary)
):
selected = True
elif event.type == pygame.MOUSEBUTTONUP:
# User released mouse buttons
selected = False
if selected:
# Move to mouse position when selected,
# the circle 'follows' the mouse
main_circle.pos = pygame.mouse.get_pos()
main_circle.recalc_boundary()
window.fill((0, 0, 0))
# Moved this draw call to outside
# your class definition
pygame.draw.circle(
window, main_circle.color,
main_circle.pos,
main_circle.radius
)
pygame.display.update()
Note: it's a bad idea to instantiate a new Circle object each game loop iteration, this'll consume lots of CPU for nothing. I believe you've done that because you placed your circle draw calls inside it, but you should really just move it out into the loop.
This question already has answers here:
Pygame mouse clicking detection
(4 answers)
Closed 1 year ago.
I am trying to make buttons using rect in Pygame. I started with the red quit button and checked if a click was inside the boundingbox of the button.
import pygame
"""import nemesis.py;"""
pygame.init();
screen = pygame.display.set_mode((400,300));
pygame.display.set_caption("menu");
menuAtivo = True;
start_button = pygame.draw.rect(screen,(0,0,240),(150,90,100,50));
continue_button = pygame.draw.rect(screen,(0,244,0),(150,160,100,50));
quit_button = pygame.draw.rect(screen,(244,0,0),(150,230,100,50));
pygame.display.flip();
while menuAtivo:
for evento in pygame.event.get():
print(evento);
if evento.type == pygame.MOUSEBUTTONDOWN:
if pygame.mouse.get_pos() >= (150,230):
if pygame.mouse.get_pos() <= (250,280):
pygame.quit();
When using rects in pygame, it's best to use the in built collision detection.
here is an example code on how to do it hope it helps you solve your problem.
Before that though i'd like to mention you should render/draw your objects withing the while loop or the wont show up.
import pygame
import sys
def main():
pygame.init()
clock = pygame.time.Clock()
fps = 60
size = [200, 200]
bg = [255, 255, 255]
screen = pygame.display.set_mode(size)
button = pygame.Rect(100, 100, 50, 50) # creates a rect object
# The rect method is similar to a list but with a few added perks
# for example if you want the position of the button you can simpy type
# button.x or button.y or if you want size you can type button.width or
# height. you can also get the top, left, right and bottom of an object
# with button.right, left, top, and bottom
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return False
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_pos = event.pos # gets mouse position
# checks if mouse position is over the button
if button.collidepoint(mouse_pos):
# prints current location of mouse
print('button was pressed at {0}'.format(mouse_pos))
screen.fill(bg)
pygame.draw.rect(screen, [255, 0, 0], button) # draw button
pygame.display.update()
clock.tick(fps)
pygame.quit()
sys.exit
if __name__ == '__main__':
main()
Another good way to create buttons on pygame (in python) is by installing the package called pygame_widgets (pip3 install pygame_widgets) on Mac or Linux and (pip install pygame_widgets) on Windows. And also make sure you have pip installed otherwise, it is not going to work.
# Importing Modules
import pygame as pg
import pygame_widgets as pw
# creating screen
pg.init()
screen = pg.display.set_mode((800, 600))
running = True
button = pw.Button(
screen, 100, 100, 300, 150, text='Hello',
fontSize=50, margin=20,
inactiveColour=(255, 0, 0),
pressedColour=(0, 255, 0), radius=20,
onClick=lambda: print('Click')
)
while running:
events = pg.event.get()
for event in events:
if event.type == pg.QUIT:
running = False
button.listen(events)
button.draw()
pg.display.update()
Hope this helps you.
TKS GUYS,
Here is my answer :
import pygame
pygame.init();
screen = pygame.display.set_mode((400,300));
pygame.display.set_caption("menu");
menuAtivo = True;
start_button = pygame.draw.rect(screen,(0,0,240),(150,90,100,50));
continue_button = pygame.draw.rect(screen,(0,244,0),(150,160,100,50));
quit_button = pygame.draw.rect(screen,(244,0,0),(150,230,100,50));
pygame.display.flip();
def startGame():
screen.fill((0,0,0));
pygame.display.flip();
import nemesis.py;
while menuAtivo:
for evento in pygame.event.get():
print(evento);
if evento.type == pygame.MOUSEBUTTONDOWN:
if pygame.mouse.get_pos()[0] >= 150 and pygame.mouse.get_pos()[1] >= 230:
if pygame.mouse.get_pos()[0] <= 250 and pygame.mouse.get_pos()[1] <= 280:
pygame.quit();
if pygame.mouse.get_pos()[0] >= 150 and pygame.mouse.get_pos()[1] >= 90:
if pygame.mouse.get_pos()[0] <= 250 and pygame.mouse.get_pos()[1] <= 140:
startGame();
I think the main problem in your code is that you compare pygame.mouse.get_pos() directly with a Tuple, which is ambiguous. You should try testing x then y separately:
while menuAtivo:
for evento in pygame.event.get():
print(evento);
if evento.type == pygame.MOUSEBUTTONDOWN:
if pygame.mouse.get_pos()[0] >= 150 and pygame.mouse.get_pos()[1] >= 230:
if pygame.mouse.get_pos()[0] <= 250 and pygame.mouse.get_pos()[1] <= 280:
pygame.quit();
I have already provided an answer on the above. Here is my another answer without the module pygame_widgets:
import pygame
import sys
# initializing the constructor
pygame.init()
# screen resolution
res = (720,720)
# opens up a window
screen = pygame.display.set_mode(res)
# white color
color = (255,255,255)
# light shade of the button
color_light = (170,170,170)
# dark shade of the button
color_dark = (100,100,100)
# stores the width of the
# screen into a variable
width = screen.get_width()
# stores the height of the
# screen into a variable
height = screen.get_height()
# defining a font
smallfont = pygame.font.SysFont('Corbel',35)
# rendering a text written in
# this font
text = smallfont.render('quit' , True , color)
while True:
for ev in pygame.event.get():
if ev.type == pygame.QUIT:
pygame.quit()
#checks if a mouse is clicked
if ev.type == pygame.MOUSEBUTTONDOWN:
#if the mouse is clicked on the
# button the game is terminated
if width/2 <= mouse[0] <= width/2+140 and height/2 <= mouse[1] <= height/2+40:
pygame.quit()
# fills the screen with a color
screen.fill((60,25,60))
# stores the (x,y) coordinates into
# the variable as a tuple
mouse = pygame.mouse.get_pos()
# if mouse is hovered on a button it
# changes to lighter shade
if width/2 <= mouse[0] <= width/2+140 and height/2 <= mouse[1] <= height/2+40:
pygame.draw.rect(screen,color_light,[width/2,height/2,140,40])
else:
pygame.draw.rect(screen,color_dark,[width/2,height/2,140,40])
# superimposing the text onto our button
screen.blit(text , (width/2+50,height/2))
# updates the frames of the game
pygame.display.update()
Hope This Helps if pygame_widgets (pip install pygame_widgets) module could not be installed in your python version.
this is my solution
class button():
def __init__(self, color, x,y,width,height, text=''):
self.color = color
self.x = x
self.y = y
self.width = width
self.height = height
self.text = text
def draw(self,win,outline=None):
#Call this method to draw the button on the screen
if outline:
pygame.draw.rect(win, outline, (self.x-2,self.y-2,self.width+4,self.height+4),0)
pygame.draw.rect(win, self.color, (self.x,self.y,self.width,self.height),0)
if self.text != '':
font = pygame.font.SysFont('comicsans', 60)
text = font.render(self.text, 1, (0,0,0))
win.blit(text, (self.x + (self.width/2 - text.get_width()/2), self.y + (self.height/2 - text.get_height()/2)))
def isOver(self, pos):
#Pos is the mouse position or a tuple of (x,y) coordinates
if pos[0] > self.x and pos[0] < self.x + self.width:
if pos[1] > self.y and pos[1] < self.y + self.height:
return True
return False
I can not seem to find the bug in my program. The program will run without errors however, my paddle image will not move. I have spent hours researching and tried multiple different changes. I am using python 3.4.1. My goal is to create a paddle game of sorts. Thank you.
# Python game
import pygame
import sys
pygame.init()
ball_image = pygame.image.load("ball.png")
ballrect = ball_image.get_rect()
paddle_image = pygame.image.load("paddle.png")
paddlerect = paddle_image.get_rect()
screen_w = 825
screen_h = 727
size = [screen_w, screen_h]
speed = [1, 1]
black = (0, 0, 0)
blue = (0,0,255)
screen = pygame.display.set_mode(size)
class paddle(object):
paddle_speed = [0, 0]
paddle_speed_d = [0, -1]
paddle_speed_u = [0, 1]
image = paddle_image
rect = image.get_rect()
x = 20
y = screen_h / 2
w = rect.width
h = rect.height
def __init__(self, side):
self.side = side
if side == "l":
x == width - 20 - w
def move_d(self):
self.rect.move(self.paddle_speed_d)
def move_u(self):
self.rect.move(self.paddle_speed_u)
pad1 = paddle("r")
#pad2 = paddle("l")
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
pad1.move_d()
if event.key == pygame.K_UP:
pad1.move_u()
ballrect = ballrect.move(speed)
if ballrect.left < 0 or ballrect.right > screen_w:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > screen_h:
speed[1] = -speed[1]
#if ballrect.bottom == 0:
#ballrect.y = screen_h
#if ballrect.top == screen_h:
#ballrect.bottom = 0
screen.fill(black)
screen.blit(ball_image, ballrect)
screen.blit(pad1.image, pad1.rect)
pygame.display.flip()
pygame.time.wait(1)
From the documentation:
move()
Returns a new rectangle that is moved by the given offset. The x and y arguments can be any integer value, positive or negative.
move_ip()
Same as the Rect.move() method, but operates in place.
If you change self.rect.move(self.paddle_speed_d) to self.rect.move_ip(self.paddle_speed_d) in move_d(), that should do the trick (likewise for move_u().
(This still leaves the problem that move_d() is only called on key down. This means you have to repeatedly press the down key to move your paddle. This may be what you want, but if it's not, consider having an update function move the paddle on every loop, and have move_d() and move_u() set the velocity of the paddle.)
Thanks for trying to help, but I discovered my problem. The format in which I saved my image was not showing movement. I changed my image and now it works.