New direction with pygame wideget

This commit is contained in:
Stephen Deaton 2024-06-15 18:07:33 -04:00
parent 9d12890ee3
commit 78aceadf5b
3 changed files with 53 additions and 2 deletions

BIN
PyGame/practice/button.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

View File

@ -0,0 +1,34 @@
import os
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
import pygame_widgets
import pygame
from pygame_widgets.button import Button
from pygame_widgets.dropdown import Dropdown
pygame.init()
win_width = 600
win_height = 480
win_bg_color = (102, 255, 255)
window = pygame.display.set_mode((win_width, win_height))
pygame.display.set_caption('Dice Roll')
window.fill(win_bg_color)
run = True
while run:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
pygame.quit()
run = False
quit()
pygame_widgets.update(events)
pygame.display.update()

View File

@ -1,4 +1,5 @@
import pygame
import sys
import pygame_menu
pygame.init()
@ -12,17 +13,33 @@ screen.fill(color)
pygame.display.set_caption('Dice Roll')
clock = pygame.time.Clock()
# button.png is 200x61
roll_img = pygame.image.load('button.png').convert_alpha()
class Button():
def __init__(self, x, y, image):
self.image = image
self.rect = self.image.get_rect()
self.rect.topleft = (x, y)
def draw(self):
screen.blit(self.image, (self.rect.x, self.rect.y))
roll_button = Button(((screen_width // 2) // 2) - (roll_img.get_width() // 2), 200, roll_img)
def set_number_dice(value: str, die_number: int):
# Do the job here !
pass
def set_dice_sides(value: str, sides: int):
# Do the job here !
pass
roll_button.draw()
run = True
while run == True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False