import turtle
def replaygame():
replay_label = turtle.Turtle()
replay_label.speed(0)
replay_label.color("White")
replay_label.penup()
replay_label.setposition(-290,280)
againornot = replay_label.textinput("Do you want to play again Y/N ?",False, align = "right", font = ("Arial" , 20, "normal"))
if againornot == Y:
True
else:
False
replaygame()
I'm not sure what the problem is. I imported turtle and I went through it twice. Here's the error I'm getting:
Traceback (most recent call last):
File "/Users/nn/Documents/sfgh.py", line 189, in <module>
replaygame()
File "/Users/nn/Documents/sfgh.py", line 158, in replaygame
againornot = replay_label.textinput("Do you want to play again Y/N ?",False, align = "right", font = ("Arial" , 20, "normal"))
AttributeError: 'Turtle' object has no attribute 'textinput'
When you have a minute, please post your error. In the meantime, I presume the error stems from here:
Try editing this line to put quotes around the Y. againornot == ’Y’
(Apologies for poor the formatting, I’m using my phone.)
Try it like this :
import turtle
def replaygame():
replay_label = turtle
replay_label.speed(0)
replay_label.color("White")
replay_label.penup()
replay_label.setposition(-290,280)
againornot = replay_label.textinput('Play Again', "Do you want to play again Y/N ?")
if againornot == Y:
True
else:
False
replaygame()
Related
i have this code in one file that is meant to pass the score_list variable to the run_game_over() in a seperate file Game_Over_Screen
from Game_Over_Screen import game_over
leaderboard = True
from Game_Over_Screen import game_over
leaderboard = True
while leaderboard:
print(score_list)
game_over.run_game_over(score_list)
leaderboard = False
running = False
this is the run_game_over() function
class game_over(Buttons, ellipse_button):
def run_game_over(self, score_list):
self.go_animation()
pygame.display.flip()
global game_over
game_over = True
while game_over:
Buttons.mouse_position(quit_icon)
Buttons.mouseclick(quit_icon)
Buttons.mouse_position(play_again_icon)
Buttons.mouseclick(play_again_icon)
for event in pygame.event.get():
pass
however when i run it i get the error:
Traceback (most recent call last):
File "C:\Users\matty\Documents\Programming Project\uno-1130\uno\src\Start.py", line 35, in <module>
game_over.run_game_over(score_list)
TypeError: run_game_over() missing 1 required positional argument: 'score_list'
Im not sure why this isnt working as i thought id set it up for the score_list variable to be an input correctly but clearly that is not the case
When I try to forward a song with .wav extension in pygame , I get an error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\default\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1884, in __call__
return self.func(*args)
File "C:\Users\default\PycharmProjects\pythonProject1\main.py", line 14, in forward
pygame.mixer.music.play(start = forwarded_pos)
pygame.error: Position not implemented for music type
Here's the code:
from tkinter import *
import pygame
root = Tk()
pygame.init()
def play():
pygame.mixer.music.load("test.wav")
pygame.mixer.music.play()
def forward():
forwarded_pos = pygame.mixer.music.get_pos() + 10
pygame.mixer.music.load("test.wav")
pygame.mixer.music.play(start = forwarded_pos)
play_button = Button(root , text = "Play song" , command = play)
play_button.grid(row = 0 , column = 0)
forward_button = Button(root , text = "Forward song" , command = forward)
forward_button.grid(row = 1 , column = 0 , pady = 10)
mainloop()
As I was continuously getting that error , I tried this:
def forward():
forwarded_pos = pygame.mixer.music.get_pos() + 10
pygame.mixer.music.set_pos(forwarded_pos)
But when I did that, I keep getting another error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\default\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1884, in __call__
return self.func(*args)
File "C:\Users\default\PycharmProjects\pythonProject1\main.py", line 13, in forward
pygame.mixer.music.set_pos(forwarded_pos)
pygame.error: set_pos unsupported for this codec
Is there any way to fix this problem?
I think forwarding is not supported in .wav format , so fixing this problem with any other format(except .mp3) will also be ok.
Get_pos and set_pos are triggering the same errors for me. You actually don't need them as you can assign the forwarded_pos when you start playing the music as follows. This doesn't seem to work for .wav but it does for .ogg and .mp3 formats.
import pygame
from os import path
pygame.init()
pygame.mixer.init()
snd_dir = path.join(path.dirname(__file__), "snd")
song = path.join(snd_dir, 'song_name.ogg')
forwarded_pos = 22
mixer = pygame.mixer.music
mixer.load(song)
mixer.play(-1, forwarded_pos)
# doesn't work for wav sounds types
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(10)
i try to make a game BUT I can not get the world load to work
fings that cud be gud to no
the var update is for the while loop
the error is in the area wer the block gets pikt and displayd.
class world_load:
def __init__(self, line):
self.type = line[0]
self.x = line[1]
self.y = line[2]
def __str__(self):
return self.type+" "+self.x+" "+self.y
with open(fillName, encoding=encoding) as file:
file.readline()
for line in file.readlines():
line = line.strip()
line = line.split(" ")
w = world_load(line)
world.append(p)
while update:
#input
for event in pygame.event.get():
if event.type == pygame.QUIT:
update = False
dis.fill(sky)
for world_load in world:
wo = world_load.split(" ")
if wo[0] == block_grass:
block_grass(wo[1],wo[2])
it's wos not the hole code
hear is the error fing:
Traceback (most recent call last):
File "C:\Users\Deltagare\Desktop\program\Game\Game.py", line 68, in <module>
wo = world_load.split(" ")
AttributeError: type object 'world_load' has no attribute 'split'
First, it is very hard to read your question because you have used poor grammar and spelling. secondly the .split() function in python is used for strings to split them into an array (list). You might be attempting to split your own class which is not a string and will not work. Or you could be attempting to call the split function within your class (This is what Python thinks you are trying to do) and will also not work because there is no split function. It is unclear what you are asking. I advise you rewrite this question to a higher standard and then people will be more able to help.
I have my code for a game here. I have commented out the displayScore(score) call in the main function to allow the program to run. When that call is uncommented the program window closes immediately after opening.
The objective of the function displayScore is to display the game score in the top left corner. Which also needs to be displayed in the right corner for the opposing player's score.
Here is the code for the game with displayScore commented out in the main function so you can run the game and everything will work. Uncomment it to see where the problem is:
ball = ballmovement(ball, ballDirX, ballDirY)
ballDirX, ballDirY = collisionwithedges(ball, ballDirX, ballDirY)
score = checkscore(paddle1, ball, score, ballDirX)
ballDirX = ballDirX * collisionwithpaddles(ball, paddle1, paddle2, ballDirX)
pygame.display.update() #updates the display to clear surface per the frame rate
FRAMECLOCK.tick(FRAMERATE) #Sets the Frames of program to defined rate
if __name__=='__main__':
main()
Just replace the line
displayScore(score)
By:
displayScore(str(score))
You are trying to use a number instead of a string to the argument of render ;) Score is an int and BASICFONT.render((score), True, WHITE)
asks for score to be a string or an array of bytes :)
I found the solution only by reading the console output which was a good indication ^^
Traceback (most recent call last):
File "test.py", line 130, in <module>
main()
File "test.py", line 118, in main
displayScore(score)
File "test.py", line 71, in displayScore
resultSurf = BASICFONT.render((score), True, WHITE)
TypeError: text must be a unicode or bytes
Im currently in an intro coding class and for my final project, i am trying to learn the pyglet module to create a game with a picture in the background, and have a character on the left that a user can make jump, and then have jumps come from the right at a set speed that the user will jump over. i need to use classes for the assignment, and im really having a hard time using creating a sprite class. heres my current code:
import pyglet
window = pyglet.window.Window(700,700)
image = pyglet.image.load('IMG_3315.jpg')#use 10x10 in. image
#image_2 = pyglet.image.load('IMG_3559.jpg')
main_batch = pyglet.graphics.Batch()
score_label = pyglet.text.Label(text="Score: 0", x=570, y=650, batch=main_batch)
the_jump = pyglet.image.load("jumpsi.png")
#horse = pyglet.sprite.Sprite(image_2, x = 50, y = 50)
# background_sound = pyglet.media.load(
# 'Documents/Leave The Night On.mp3',
# streaming=False)
class Jump(pyglet.sprite.Sprite):
def __init__(self, img, x=0, y=0, blend_src=770, blend_dest=771, batch=None, group=None, usage='dynamic', subpixel=False):
self.img = the_jump
self.x = 50
self.y = 50
def draw(self):
self.draw()
# verticle = Jump('verticle')
#window.event
def on_draw():
window.clear()
image.blit(0, 0)
main_batch.draw()
window = Jump()
#horse.draw()
#background_sound.play()
if __name__ == "__main__":
sprite = Jump()
pyglet.app.run()
i know its probably wrong but everything else i have tried (using preexisting games as examples) hasn't worked either.
my current error message is:
Traceback (most recent call last):
File "jumper.py", line 39, in <module>
sprite = Jump()
TypeError: __init__() takes at least 2 arguments (1 given)
im just really stuck and have been trying to figure this out for hours and not made any leeway. any help you can offer would be greatly appreciated. Thanks so much!
UPDATE: i recently changed the code, noticing the problem that Gustav pointed out, and change the end call to
if __name__ == "__main__":
sprite = Jump(the_jump)
pyglet.app.run()
but now i get the error
Traceback (most recent call last):
File "jumper.py", line 39, in <module>
sprite = Jump(the_jump)
File "jumper.py", line 21, in __init__
self.x = 50
File "/Library/Python/2.7/site-packages/pyglet/sprite.py", line 459, in _set_x
self._update_position()
File "/Library/Python/2.7/site-packages/pyglet/sprite.py", line 393, in _update_position
img = self._texture
AttributeError: 'Jump' object has no attribute '_texture'
The error message is telling you exactly which line the error is in and exactly what is wrong. You are initializing the Jump class without passing in an argument for the required parameter img.
You can fix this by either changing the initialization method or your call to Jump().
Here's an example for how to read Python's traceback.