Python Forum
[split] TypeError: 'int' object is not callable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] TypeError: 'int' object is not callable
#1
Dear deanhystad,

I tried to create a form in tkinter because, as you mentioned, the player shouldn't have to install some extra packages.
(I'm planning to create an exe to give to someone.)

The form should let the user choose which tracks should be randomly played in the background (while playing the game).
What I try to achieve is:
First, the user is told to select the tracks he likes.
These tracks are appended to the list listl.
Then the playlist should be generated by choosing randomly from listl.
Doing so, I try to generate a playlist, which is different each time it is generated.
When a playlist ends, the next playlist is played and so on...
I try to let the user randomly hear only tracks he likes.

I've got a specific question:

In function "insert_into_playlist" is the following error:
Error:
D:\Daten\tkintermenu\main.py:56: DeprecationWarning: The *random* parameter to shuffle() has been deprecated since Python 3.9 and will be removed in a subsequent version. playlist.append(random.shuffle(listl, 1)) Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\...\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__ return self.func(*args) File "D:\Daten\tkintermenu\main.py", line 82, in isChecked insert_into_playlist(listl, playlist) File "D:\Daten\tkintermenu\main.py", line 56, in insert_into_playlist playlist.append(random.shuffle(listl, 1)) File "C:\Users\...\AppData\Local\Programs\Python\Python310\lib\random.py", line 403, in shuffle j = floor(random() * (i + 1)) TypeError: 'int' object is not callable
Would you please have a look on my attempt and could you tell me what I'm doing wrong (when I try to shuffle the tracks from list listl = filling the playlist)?
import tkinter, pygame, random
from tkinter import *
master = Tk()
master.geometry('500x400')
pygame.init()

a = "Adeline Yeo (HP) - Kite Fly High"
b = "Nul Tiel Records - Fireflies"
c = "cryptic scenery - Endzeit Endlos"
d = "cryptic scenery - Helix Spire"
e = "cryptic scenery - Minsk Metro"
f = "cryptic scenery - Stazione Termini"
g = "cryptic scenery - The Future was Japanese"
h = "Ketsa - Holding The Line"
i = "Maarten Schellekens - Salt Lake Swerve"
j = "Strobotone - Dance Track"

pygame.mixer.init()
pygame.mixer.music.set_volume(0.7)

def start_playlist(playList):
    # Loading first audio file into our player
    pygame.mixer.music.load(playList[0])
    playList.pop(0)
    # Playing our music
    pygame.mixer.music.play()
    if len(playList) > 1:
        pygame.mixer.music.queue(playList[0])
        playList.pop(0)
    # setting up an end event which host an event
    # after the end of every song
    pygame.mixer.music.set_endevent(pygame.USEREVENT)
    running = True
    while running:
        # checking if any event has been
        # hosted at time of playing
        for event in pygame.event.get():
            # A event will be hosted
            # after the end of every song
            if event.type == pygame.USEREVENT:
                if len(playList) > 0:
                    pygame.mixer.music.queue(playList[0])
                    playList.pop(0)
            if not pygame.mixer.music.get_busy():
                running = False
                break


def insert_into_listl(listl, track):
    # Adding songs file in our listl
    listl.append(track)

def insert_into_playlist(listl, playlist):
    # Adding songs file in our playlist
    for i in range(len(listl)):
        playlist.append(random.shuffle(listl, 1))
    start_playlist(playlist)

def isChecked():
    listl = []
    playlist = []
    if cb1.get() is True:
        insert_into_listl(listl, a)
    if cb2.get() is True:
        insert_into_listl(listl, b)
    if cb3.get() is True:
        insert_into_listl(listl, c)
    if cb4.get() is True:
        insert_into_listl(listl, d)
    if cb5.get() is True:
        insert_into_listl(listl, e)
    if cb6.get() is True:
        insert_into_listl(listl, f)
    if cb7.get() is True:
        insert_into_listl(listl, g)
    if cb8.get() is True:
        insert_into_listl(listl, h)
    if cb9.get() is True:
        insert_into_listl(listl, i)
    if cb10.get() is True:
        insert_into_listl(listl, j)
    insert_into_playlist(listl, playlist)

def play1():
    pygame.mixer.music.load(a + ".mp3")
    pygame.mixer.music.play()

def play2():
    pygame.mixer.music.load(b + ".mp3")
    pygame.mixer.music.play()

def play3():
    pygame.mixer.music.load(c + ".mp3")
    pygame.mixer.music.play()

def play4():
    pygame.mixer.music.load(d + ".mp3")
    pygame.mixer.music.play()

def play5():
    pygame.mixer.music.load(e + ".mp3")
    pygame.mixer.music.play()

def play6():
    pygame.mixer.music.load(f + ".mp3")
    pygame.mixer.music.play()

def play7():
    pygame.mixer.music.load(g + ".mp3")
    pygame.mixer.music.play()

def play8():
    pygame.mixer.music.load(h + ".mp3")
    pygame.mixer.music.play()

def play9():
    pygame.mixer.music.load(i + ".mp3")
    pygame.mixer.music.play()

def play10():
    pygame.mixer.music.load(j + ".mp3")
    pygame.mixer.music.play()

l = Label(master, text="Welche tracks sollen zufällig gespielt werden (mit playlist)?", font=('arial', 12, 'bold', 'italic'))
l.place(x=0, y=0)
button1 = tkinter.Button(master, text="reinhören", command=play1)
button1.place(x=0, y=25)
button2 = tkinter.Button(master, text="reinhören", command=play2)
button2.place(x=0, y=50)
button3 = tkinter.Button(master, text="reinhören", command=play3)
button3.place(x=0, y=75)
button4 = tkinter.Button(master, text="reinhören", command=play4)
button4.place(x=0, y=100)
button5 = tkinter.Button(master, text="reinhören", command=play5)
button5.place(x=0, y=125)
button6 = tkinter.Button(master, text="reinhören", command=play6)
button6.place(x=0, y=150)
button7 = tkinter.Button(master, text="reinhören", command=play7)
button7.place(x=0, y=175)
button8 = tkinter.Button(master, text="reinhören", command=play8)
button8.place(x=0, y=200)
button9 = tkinter.Button(master, text="reinhören", command=play9)
button9.place(x=0, y=225)
button10 = tkinter.Button(master, text="reinhören", command=play10)
button10.place(x=0, y=250)

cb1=BooleanVar()
cb2=BooleanVar()
cb3=BooleanVar()
cb4=BooleanVar()
cb5=BooleanVar()
cb6=BooleanVar()
cb7=BooleanVar()
cb8=BooleanVar()
cb9=BooleanVar()
cb10=BooleanVar()

Checkbutton1 = Checkbutton(master, text=a, variable=cb1)
Checkbutton1.place(x=75, y=25)
Checkbutton2 = Checkbutton(master, text=b, variable=cb2)
Checkbutton2.place(x=75, y=50)
Checkbutton3 = Checkbutton(master, text=c, variable=cb3)
Checkbutton3.place(x=75, y=75)
Checkbutton4 = Checkbutton(master, text=d, variable=cb4)
Checkbutton4.place(x=75, y=100)
Checkbutton5 = Checkbutton(master, text=e, variable=cb5)
Checkbutton5.place(x=75, y=125)
Checkbutton6 = Checkbutton(master, text=f, variable=cb6)
Checkbutton6.place(x=75, y=150)
Checkbutton7 = Checkbutton(master, text=g, variable=cb7)
Checkbutton7.place(x=75, y=175)
Checkbutton8 = Checkbutton(master, text=h, variable=cb8)
Checkbutton8.place(x=75, y=200)
Checkbutton9 = Checkbutton(master, text=i, variable=cb9)
Checkbutton9.place(x=75, y=225)
Checkbutton10 = Checkbutton(master, text=j, variable=cb10)
Checkbutton10.place(x=75, y=250)
button11 = tkinter.Button(master, text="ausgewählte tracks zu playlist hinzufügen", command=isChecked)
button11.place(x=75, y=275)

mainloop()
Have a nice weekend and many thanks for your effort!
Reply
#2
https://docs.python.org/3/library/random...om.shuffle Wrote:Shuffle the sequence x in place.

The optional argument random is a 0-argument function returning a random float in [0.0, 1.0); by default, this is the function random().

To shuffle an immutable sequence and return a new shuffled list, use sample(x, k=len(x)) instead.

Note that even for small len(x), the total number of permutations of x can quickly grow larger than the period of most random number generators. This implies that most permutations of a long sequence can never be generated. For example, a sequence of length 2080 is the largest that can fit within the period of the Mersenne Twister random number generator.

Deprecated since version 3.9, will be removed in version 3.11: The optional parameter random.

you have passed an int to the optional random argument
playlist.append(random.shuffle(listl, 1))
remove the int
playlist.append(random.shuffle(listl))
Reply
#3
I think Yoriz's analysis is off. All the info is correct, but I think you were trying to do this:
playlist.append(random.shuffle(listl)[1])
As Yoriz mentions, shuffle() works in place, changing the order of the original list. And working in place it returns None instead of a shuffled list. random.choice() is a better fit.
playlist.append(random.choice(listl))
Or maybe you were trying to get a random.sample() of size 1. It doesn't matter because there is no reason to use the random library.

This is Bad. This is like having a variable for each brick in your breakout game.
a = "Adeline Yeo (HP) - Kite Fly High"
b = "Nul Tiel Records - Fireflies"
c = "cryptic scenery - Endzeit Endlos"
d = "cryptic scenery - Helix Spire"
e = "cryptic scenery - Minsk Metro"
f = "cryptic scenery - Stazione Termini"
g = "cryptic scenery - The Future was Japanese"
h = "Ketsa - Holding The Line"
i = "Maarten Schellekens - Salt Lake Swerve"
j = "Strobotone - Dance Track"
This is slightly better:
songs= [
    "Adeline Yeo (HP) - Kite Fly High",
    "Nul Tiel Records - Fireflies",
    "cryptic scenery - Endzeit Endlos",
    "cryptic scenery - Helix Spire",
    "cryptic scenery - Minsk Metro",
    "cryptic scenery - Stazione Termini",
    "cryptic scenery - The Future was Japanese",
    "Ketsa - Holding The Line",
    "Maarten Schellekens - Salt Lake Swerve",
    "Strobotone - Dance Track"]
If you have a collection, use a collection, not individual variables.

Now that songs are a collection, you can treat them as a collection and not individual songs. Songs are not the only collections in your code. The check buttons are a collection, and the boolean variables. Your program should have 3 variables associated with songs, not 30, and you really don't need 3. Here I let tkinter remember the check buttons and boolean variables so the only variable I need is songs.
import tkinter as tk

songs= [
    "Adeline Yeo (HP) - Kite Fly High",
    "Nul Tiel Records - Fireflies",
    "cryptic scenery - Endzeit Endlos",
    "cryptic scenery - Helix Spire",
    "cryptic scenery - Minsk Metro",
    "cryptic scenery - Stazione Termini",
    "cryptic scenery - The Future was Japanese",
    "Ketsa - Holding The Line",
    "Maarten Schellekens - Salt Lake Swerve",
    "Strobotone - Dance Track"]

playlist = []

root = tk.Tk()

def edit_playlist(var, song):
    """Add or remove song from playlist based on value of var"""
    if var.get():
        if not song in playlist:
            playlist.append(song)
    elif song in playlist:
        playlist.remove(song)
    print(playlist)

for song in songs:
    var = tk.BooleanVar()
    tk.Checkbutton(
            root,
            variable=var,
            text=song,
            command=lambda v=var, s=song: edit_playlist(v, s)).pack(anchor="w")

root.mainloop()
If I was writing this I would not hard code the songs. I would have a folder with music and built the list by reading the folder. But I would not be writing this at all. I would have that song folder associated with the game. You could package some default songs in the folder, but if the players wanted different music they could delete your songs and copy their own songs to the folder. When the game starts up it reads the song filenames from the folder. The folder is your playlist and there is no need for a playlist editor. If you want to randomize the playlist then you can use the random library, but that code belongs in the breakout game.

If you want to write a media player that uses tkinter and pygame, do that. That could be fun searching for music files, making play lists, implementing play and pause and fastforward and reverse. It would be a great way to learn tkinter and GUI programming.
Reply
#4
Dear deanhystad,

thanks a lot for your effort!!
I started to use tkinter and getting informed how to create an exe.
I've noticed a wrongdoing of the ball (15x15 pixel), it bounces inside the paddle (128x24 pixel).
I tried to fix it, but finally I failed.
Would you please have a look on it?
In the moment I'm professionally required so the code concerning the music (and the pyqt) are in an old state - please ignore this.
At the weekend I will be able to work on this.
After searching the web I found "sample" too.
import random, math, pygame
from PIL import Image
from itertools import product
from PyQt6.QtWidgets import QLabel, QRadioButton, QVBoxLayout, QApplication, QWidget
from PyQt6.QtGui import *

# Define colors used by the game.
TEXT_COLOR = (255, 255, 255)
FOREGROUND = (0, 0, 0)  # Recolor image pixels that are this color
TRANSPARENT = (255, 255, 255)  # Make image pixels this color transparent
BALL_COLOR = (255, 255, 255)
PADDLE_COLOR = (255, 255, 255)
BRICK_COLORS = ((255, 0, 0), (255, 50, 0), (255, 100, 0), (255, 150, 0), (255, 200, 0), (255, 255, 0))
BRICK_COORDS = [
    (32, 32), (64, 32), (96, 32), (160, 32), (288, 32), (320, 32), (352, 32), (416, 32), (448, 32),
    (480, 32), (576, 32), (608, 32), (640, 32), (32, 64), (160, 64), (288, 64), (352, 64), (416, 64),
    (480, 64), (576, 64), (640, 64), (32, 96), (160, 96), (288, 96), (352, 96), (416, 96), (480, 96),
    (576, 96), (640, 96), (32, 128), (64, 128), (96, 128), (160, 128), (288, 128), (352, 128), (416, 128),
    (448, 128), (480, 128), (576, 128), (608, 128), (640, 128), (32, 160), (160, 160), (288, 160), (352, 160),
    (416, 160), (448, 160), (576, 160), (640, 160), (32, 192), (160, 192), (288, 192), (352, 192), (416, 192),
    (480, 192), (576, 192), (640, 192), (32, 224), (160, 224), (192, 224), (224, 224), (288, 224), (320, 224),
    (352, 224), (416, 224), (512, 224), (576, 224), (640, 224)]

# Define some image files.  These are not your files
BALL_IMAGE = "ball.png"
PADDLE_IMAGE = "paddle.png"
BRICK_FILES = (("brick0.png", "brick1.png", "brick2.png"), ("bbrick0.png", "bbrick1.png", "bbrick2.png"))
BACKGROUND_IMAGE = pygame.image.load("Hintergrund.png")
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 578
SCORE_POSITION = (SCREEN_WIDTH - 150, SCREEN_HEIGHT - 30)


def create_image(file, color=None):
    """
    Create image from a file.  If color is specified, replace all FOREGROUND
    pixels with color pixels.  Modify image so TRANSPARENT colored pixels are
    transparent.
    """
    if color:
        # Recolor the image
        image = Image.open(file).convert("RGB")
        for xy in product(range(image.width), range(image.height)):
            if image.getpixel(xy) == FOREGROUND:
                image.putpixel(xy, color)
        image = pygame.image.fromstring(image.tobytes(), image.size, "RGB")
    else:
        image = pygame.image.load(file)
    image.set_colorkey(TRANSPARENT)
    return image.convert()


class EnhancedSprite(pygame.sprite.Sprite):
    """
    Sprite with image and rectangle.  I expose some of my rectangle's
    properties.
    """

    def __init__(self, image, group=None, **kwargs):
        super().__init__(**kwargs)
        self.image = image
        self.rect = image.get_rect()
        if group is not None:
            group.add(self)

    def at(self, x, y):
        """Convenience method for setting my position"""
        self.x = x
        self.y = y
        return self

    # Properties below expose properties of my rectangle so you can use
    # self.x = 10 or self.centery = 30 instead of self.rect.x = 10
    @property
    def x(self):
        return self.rect.x

    @x.setter
    def x(self, value):
        self.rect.x = value

    @property
    def y(self):
        return self.rect.y

    @y.setter
    def y(self, value):
        self.rect.y = value

    @property
    def centerx(self):
        return self.rect.centerx

    @centerx.setter
    def centerx(self, value):
        self.rect.centerx = value

    @property
    def centery(self):
        return self.rect.centery

    @centery.setter
    def centery(self, value):
        self.rect.centery = value

    @property
    def right(self):
        return self.rect.right

    @right.setter
    def right(self, value):
        self.rect.right = value

    @property
    def bottom(self):
        return self.rect.bottom

    @bottom.setter
    def bottom(self, value):
        self.rect.bottom = value


class Brick(EnhancedSprite):
    """
    A target for the ball.  After I take some number of hits I die.
    Number of hits I can take is in range 1 to 3.  Hits is randomly
    selected if not specified.

    Specify brick color using (R, G, B) format.  If color not specified
    a color is selected based on the row.
    """
    group = pygame.sprite.Group()

    def __init__(self, x, y, image_files=None, color=None, hits=None):
        color = color or random.choice(BRICK_COLORS)
        hits = hits or random.choice((1, 1, 1, 2, 2, 3))
        self.value = self.hits = max(1, min(3, hits))
        image_files = image_files or random.choice(BRICK_FILES)
        self.images = [create_image(file, color) for file in image_files]
        super().__init__(self.images[self.hits - 1], self.group)
        self.at(x, y)

    def __len__(self):
        """Return how many bricks remaining"""
        return len(self.group)

    def hit(self, score):
        """
        I was hit!  Update my appearance or die based on my hit total.
        Return my value if I was killed.
        """
        self.hits -= 1
        if self.hits > 0:
            self.image = self.images[self.hits - 1]
            return 0
        self.kill()
        return self.value


class Paddle(EnhancedSprite):
    """The sprite the player moves around to redirect the ball"""
    group = pygame.sprite.Group()

    def __init__(self, bottom):
        super().__init__(create_image(PADDLE_IMAGE, PADDLE_COLOR), self.group)
        self.bottom = bottom
        self.xmin = self.rect.width // 2  # Compute paddle x range.
        self.xmax = SCREEN_WIDTH - self.xmin

    def move(self, x):
        """Move to follow the cursor.  Clamp to window bounds"""
        self.centerx = max(self.xmin, min(self.xmax, x))


class LifeCounter():
    """Keep track of lives count.  Display lives remaining using ball image"""

    def __init__(self, x, y, count=5):
        self.x, self.y = x, y
        self.image = create_image(BALL_IMAGE, BALL_COLOR)
        self.spacing = self.image.get_width() + 5
        self.group = pygame.sprite.Group()
        self.reset(count)

    def reset(self, count):
        """Reset number of lives"""
        self.count = count
        for c in range(count - 1):
            EnhancedSprite(self.image, self.group).at(self.x + c * self.spacing, self.y)

    def __len__(self):
        """Return number of lives remaining"""
        return self.count

    def kill(self):
        """Reduce number of lives"""
        if self.count > 1:
            self.group.sprites()[-1].kill()
        self.count = max(0, self.count - 1)


class Ball(EnhancedSprite):
    """Ball bounces around colliding with walls, paddles and bricks"""
    group = pygame.sprite.Group()

    def __init__(self, paddle, lives, speed=5):
        super().__init__(create_image(BALL_IMAGE, BALL_COLOR), self.group)
        self.paddle = paddle
        self.lives = lives
        self.speed = speed
        self.dx = self.dy = 0
        self.xmax = SCREEN_WIDTH - self.rect.width
        self.ymax = paddle.bottom - self.rect.height
        self.reset(0)

    def reset(self, score=None):
        """Reset for a new game"""
        self.active = False
        if score is not None:
            self.score = score

    def start(self):
        """Start moving the ball in a random direction"""
        angle = random.random() - 0.5  # Launch angle limited to about +/-60 degrees
        self.dx = int(self.speed * math.sin(angle))
        self.dy = -int(self.speed * math.cos(angle))
        self.active = True

    def move(self):
        """Update the ball position.  Check for collisions with bricks, walls and the paddle"""
        if not self.active:
            # Sit on top of the paddle
            self.centerx = self.paddle.centerx
            self.bottom = self.paddle.y - 2
            return self

        # Did I hit some bricks?  Update the bricks and the score
        x1, y1 = self.x, self.y
        x2, y2 = x1 + self.dx, y1 + self.dy
        if (xhits := pygame.sprite.spritecollide(self.at(x2, y1), Brick.group, False)):
            self.dx = -self.dx
        if (yhits := pygame.sprite.spritecollide(self.at(x1, y2), Brick.group, False)):
            self.dy = -self.dy
        if (hits := set(xhits) or set(yhits)):
            for brick in hits:
                self.score += brick.hit(self.score)

        # Did I hit a wall?
        if x2 <= 0 or x2 >= self.xmax:
            self.dx = -self.dx
            hits = True
        if y2 <= 0:
            self.dy = abs(self.dy)
            hits = True

        # Did I hit or get past the paddle?
        if y2 >= self.paddle.y:
            # Did it get past the paddle?
            if self.x > self.paddle.right or self.right < self.paddle.x:
                self.lives.kill()
                self.active = False
            else:
                # I hit the paddle.  Compute angle of reflection
                bangle = math.atan2(-self.dx, self.dy)  # Ball angle of approach
                pangle = math.atan2(self.centerx - self.paddle.centerx, 30)  # Paddle angle
                rangle = (pangle - bangle) / 2  # Angle of reflection
                self.dx = math.sin(rangle) * self.speed
                self.dy = -math.cos(rangle) * self.speed
                hits = True

        if hits:
            self.at(x1, y1)
        else:
            self.at(x2, y2)


def main():
    app = QApplication([])

    a = "Adeline Yeo (HP) - Kite Fly High"
    b = "Bio Unit - Lights"
    c = "cryptic scenery - Endzeit Endlos"
    d = "cryptic scenery - Helix Spire"
    e = "cryptic scenery - Minsk Metro"
    f = "cryptic scenery - Stazione Termini"
    g = "cryptic scenery - The Future was Japanese"
    h = "Ketsa - Holding The Line"
    i = "Maarten Schellekens - Salt Lake Swerve"
    j = "Strobotone - Dance Track"

    myFontFett = QFont("TimesNewRoman", 12)
    myFontFett.setBold(True)
    myFont = QFont("TimesNewRoman", 12)

    label = QLabel("Welche Musik soll laufen? - bitte anklicken...")
    label.setFont(myFontFett)
    rb1 = QRadioButton(a)
    rb1.setFont(myFont)
    rb2 = QRadioButton(b)
    rb2.setFont(myFont)
    rb3 = QRadioButton(c)
    rb3.setFont(myFont)
    rb4 = QRadioButton(d)
    rb4.setFont(myFont)
    rb5 = QRadioButton(e)
    rb5.setFont(myFont)
    rb6 = QRadioButton(f)
    rb6.setFont(myFont)
    rb7 = QRadioButton(g)
    rb7.setFont(myFont)
    rb8 = QRadioButton(h)
    rb8.setFont(myFont)
    rb9 = QRadioButton(i)
    rb9.setFont(myFont)
    rb10 = QRadioButton(j)
    rb10.setFont(myFont)
    label1 = QLabel("Musik von:")
    label1.setFont(myFont)
    label2 = QLabel("https://freemusicarchive.org/")
    label2.setFont(myFontFett)
    label3 = QLabel("Hintergrundbild von:")
    label3.setFont(myFont)
    label4 = QLabel("Joshgmit auf Pixabay")
    label4.setFont(myFontFett)

    layout = QVBoxLayout()

    layout.addWidget(label)
    layout.addWidget(rb1)
    layout.addWidget(rb2)
    layout.addWidget(rb3)
    layout.addWidget(rb4)
    layout.addWidget(rb5)
    layout.addWidget(rb6)
    layout.addWidget(rb7)
    layout.addWidget(rb8)
    layout.addWidget(rb9)
    layout.addWidget(rb10)
    layout.addWidget(label1)
    layout.addWidget(label2)
    layout.addWidget(label3)
    layout.addWidget(label4)

    rb1.setChecked(True)
    pygame.mixer.init()

    def play(self):
        if rb1.isChecked():
            pygame.mixer.music.load(a + ".mp3")
        if rb2.isChecked():
            pygame.mixer.music.load(b + ".mp3")
        if rb3.isChecked():
            pygame.mixer.music.load(c + ".mp3")
        if rb4.isChecked():
            pygame.mixer.music.load(d + ".mp3")
        if rb5.isChecked():
            pygame.mixer.music.load(e + ".mp3")
        if rb6.isChecked():
            pygame.mixer.music.load(f + ".mp3")
        if rb7.isChecked():
            pygame.mixer.music.load(g + ".mp3")
        if rb8.isChecked():
            pygame.mixer.music.load(h + ".mp3")
        if rb9.isChecked():
            pygame.mixer.music.load(i + ".mp3")
        if rb10.isChecked():
            pygame.mixer.music.load(j + ".mp3")
        pygame.mixer.music.set_volume(0.7)
        pygame.mixer.music.play(-1)

    rb1.clicked.connect(play)
    rb2.clicked.connect(play)
    rb3.clicked.connect(play)
    rb4.clicked.connect(play)
    rb5.clicked.connect(play)
    rb6.clicked.connect(play)
    rb7.clicked.connect(play)
    rb8.clicked.connect(play)
    rb9.clicked.connect(play)
    rb10.clicked.connect(play)

    widget = QWidget()
    widget.setLayout(layout)
    widget.show()

    app.exec()

    """Play game until out of lives or out of bricks"""

    def displayText(text, font, pos=None, color=TEXT_COLOR):
        text = font.render(text, 1, color)
        if pos is None:
            pos = ((SCREEN_WIDTH - text.get_width()) // 2, (SCREEN_HEIGHT - text.get_height()) // 2)
        screen.blit(text, pos)

    pygame.init()
    screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
    pygame.display.set_caption("Breakout")
    clock = pygame.time.Clock()
    allsprites = pygame.sprite.Group()
    score_font = pygame.font.Font(None, 34)

    try:
        level = 1
        lives = LifeCounter(10, SCREEN_HEIGHT - 30)
        paddle = Paddle(bottom=SCREEN_HEIGHT - 40)
        ball = Ball(paddle, lives)
        allsprites.add(paddle.group, lives.group, ball.group)

        while len(lives) > 0:
            # Start new board.  Could have different layouts for each level
            for coord in BRICK_COORDS:
                Brick(*coord)
            allsprites.add(Brick.group)

            # Play until out of bricks or lives
            while len(lives) > 0 and len(Brick.group):
                clock.tick(60)
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        raise SystemExit
                    elif event.type == pygame.MOUSEMOTION:
                        paddle.move(event.pos[0])
                    elif event.type == pygame.MOUSEBUTTONUP:
                        if not ball.active:
                            ball.start()
                ball.move()
                screen.blit(BACKGROUND_IMAGE, (0, 0))
                displayText(f"Score: {ball.score}", font=score_font, pos=SCORE_POSITION)
                allsprites.draw(screen)
                pygame.display.flip()

            # Display results
            if len(lives) == 0:
                displayText("Game over", font=pygame.font.Font(None, 74))
            elif len(Brick.group) == 0:
                level += 1
                displayText(f"Level {level}", font=pygame.font.Font(None, 74))
                ball.speed *= 1.25
                ball.reset(ball.score)
            pygame.display.flip()
            pygame.time.wait(3000)
    finally:
        pygame.quit()


if __name__ == "__main__":
    main()
concernig the wrongdoing of the ball:
self.ymax = paddle.bottom - self.rect.height (line 213)
Is the failure there? I tried to self.ymax=paddle.top

If the wrongdoing of the ball could be fixed then the gameplay would be finished.

Thanks a lot for your patience!!
Reply
#5
You should start a new thread. This does not relate to your tkinter question.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: cannot pickle ‘_asyncio.Future’ object Abdul_Rafey 1 400 Mar-07-2024, 03:40 PM
Last Post: deanhystad
  error in class: TypeError: 'str' object is not callable akbarza 2 514 Dec-30-2023, 04:35 PM
Last Post: deanhystad
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 757 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  TypeError: 'NoneType' object is not callable akbarza 4 1,010 Aug-24-2023, 05:14 PM
Last Post: snippsat
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 1,375 Aug-23-2023, 06:21 PM
Last Post: deanhystad
  Need help with 'str' object is not callable error. Fare 4 853 Jul-23-2023, 02:25 PM
Last Post: Fare
  TypeError: 'float' object is not callable #1 isdito2001 1 1,087 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  TypeError: a bytes-like object is required ZeroX 13 4,162 Jan-07-2023, 07:02 PM
Last Post: deanhystad
  'SSHClient' object is not callable 3lnyn0 1 1,174 Dec-15-2022, 03:40 AM
Last Post: deanhystad
  TypeError: 'float' object is not callable TimofeyKolpakov 3 1,459 Dec-04-2022, 04:58 PM
Last Post: TimofeyKolpakov

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020