[Python] Same behaviour can't be achieved with lambda [duplicate]

Discussão em 'Python' iniciado por Stack, Julho 28, 2025.

  1. Stack

    Stack Membro Participativo

    button.bind("<Button-1>", partial(self.handle_click, row, col))

    def handle_click(self, row, col, event):
    cell = event.widget
    updated = self.update_cell(cell, row, col)

    if not updated:
    self.display.config(text=f"Cell occupied!", fg="green")
    return

    winner = self.gameplay.get_winner()
    if winner:
    player = winner
    self.display.config(text=f"{player.label} won!", fg=player.colour)
    elif self.gameplay.has_tied():
    self.display.config(text="Game Tied!", fg="black")
    else:
    self.gameplay.switch_player()
    player = self.gameplay.currentplayer
    self.display.config(text=f"{player.label}'s turn!", fg=player.colour)


    If I replace button.bind with lambda function I won't get the same behaviour i.e. label turning from black to the current player color. Originally the code was with lambda but it directly placed the label in the player's color. Why is this difference occurring?

    Continue reading...

Compartilhe esta Página