-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
43 lines (35 loc) · 1.26 KB
/
test.py
File metadata and controls
43 lines (35 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pygame
import pygame_widgets
from pygame_widgets.button import Button
# Set up Pygame
pygame.init()
win = pygame.display.set_mode((600, 600))
# Creates the button with optional parameters
button = Button(
# Mandatory Parameters
win, # Surface to place button on
100, # X-coordinate of top left corner
100, # Y-coordinate of top left corner
300, # Width
150, # Height
# Optional Parameters
text='Hello', # Text to display
fontSize=50, # Size of font
margin=20, # Minimum distance between text/image and edge of button
inactiveColour=(200, 50, 0), # Colour of button when not being interacted with
hoverColour=(150, 0, 0), # Colour of button when being hovered over
pressedColour=(0, 200, 20), # Colour of button when being clicked
radius=20, # Radius of border corners (leave empty for not curved)
onClick=lambda: print('Click') # Function to call when clicked on
)
run = True
while run:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
pygame.quit()
run = False
quit()
win.fill((255, 255, 255))
pygame_widgets.update(events) # Call once every loop to allow widgets to render and listen
pygame.display.update()