Skip to content

Commit 3acc174

Browse files
authored
add "command" argument
1 parent de79695 commit 3acc174

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pygame/button-hover/example-1.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030

3131
class Button():
3232

33-
def __init__(self, text, x=0, y=0, width=100, height=50):
33+
def __init__(self, text, x=0, y=0, width=100, height=50, command=None):
3434

3535
self.text = text
36-
36+
self.command = command
37+
3738
self.image_normal = pygame.Surface((width, height))
3839
self.image_normal.fill(GREEN)
3940

@@ -75,6 +76,8 @@ def handle_event(self, event):
7576
elif event.type == pygame.MOUSEBUTTONDOWN:
7677
if self.hovered:
7778
print('Clicked:', self.text)
79+
if self.command:
80+
self.command()
7881

7982

8083
# === FUNCTIONS === (lower_case names)

0 commit comments

Comments
 (0)