'Pygame Menu Button doesn't disappear after menu.clear()

I'm trying to develop a kind of slither.io in Python. Everything works fine until now. I want to place a death screen at the end of the game but it won't work at all.

When starting the program, I create one menu and change the buttons on it. There are buttons like start, close, ... . When the player presses the start button, there should be a pause button in the top right corner and this works fine. But if the player dies this button should disappear but it won't. It just stays there but loses its functions. I know that the new buttons of the end screen are there because I can click on them but I can't see them.

I've tried menu.clear() and added the buttons of the death screen on it. That's how it worked for the other parts of the menu.

#That's the function which I'm calling from another object.
def dead(self):
    """Opens the death menu when player dies.
    """
    self.menu.clear()
    self.menu.add.label('Your score: ')
    self.menu.add.button('Start new game', self.start)
    self.menu.add.button('Back to home', self.show_start_menu)

I don't know if it's because I'm adding the pause button like this?

def _display_pause_button(self):
    """This functions adds the pause-button to the window.
    """
    offset = 25
    self.button = self.menu.add.button('x', self.pause, button_id = 'x')
    self.menu.render()
    self.button.set_position(self.window_size[0]-offset, offset)

So I think the method works correctly but I'm missing the rendering function or something like this. As I already said: the buttons are there but they are somehow in the background. But the pause button just doesn't get removed.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source