Updated Example
This commit is contained in:
parent
f317473664
commit
b76da75ea3
37
main.py
37
main.py
@ -20,16 +20,17 @@ slider_y = pygui.Slider((20, 100), (200, 20), min_value=0, max_value=HEIGHT, sta
|
||||
label_x = pygui.Label("X: ", (20, 35), 15)
|
||||
label_y = pygui.Label("Y: ", (20, 85), 15)
|
||||
|
||||
knob = pygui.Knob((25,150), 40, 0, 105.5, 1, 1)
|
||||
# Add a button to reset the position
|
||||
reset_button = pygui.Button("Reset Position", (20, 150), (150, 40))
|
||||
|
||||
knob = pygui.Knob((25, 200), 40, 0, 255, 1, 1)
|
||||
|
||||
fps_label = pygui.Label("FPS: ", (5, 50), 20)
|
||||
position_label = pygui.Label("POS: ", (5, 70), 20)
|
||||
color_label = pygui.Label("COL: ", (5, 90), 20)
|
||||
|
||||
|
||||
|
||||
# Create windows and add them to the window stack
|
||||
window = pygui.Window("Move Object", (600, 50), (250, 150), elements=[label_x, label_y, slider_x, slider_y])
|
||||
window = pygui.Window("Move Object", (600, 50), (250, 200), elements=[label_x, label_y, slider_x, slider_y, reset_button])
|
||||
debug_window = pygui.Window("Info", (0, 0), (150, HEIGHT), elements=[fps_label, position_label, color_label, knob], fixed=True)
|
||||
|
||||
# Add windows to the global window stack
|
||||
@ -40,7 +41,6 @@ window_stack.append(debug_window)
|
||||
object_pos = [WIDTH // 2, HEIGHT // 2]
|
||||
object_size = (50, 50)
|
||||
|
||||
|
||||
DEBUG = True
|
||||
|
||||
def handle_window_focus():
|
||||
@ -72,14 +72,24 @@ def draw_gui():
|
||||
object_pos[0] = int(slider_x.value) # Update x position based on the x-slider
|
||||
object_pos[1] = int(slider_y.value) # Update y position based on the y-slider
|
||||
|
||||
# Check if the reset button is clicked
|
||||
if reset_button.is_clicked:
|
||||
# Reset the object position
|
||||
object_pos[0] = WIDTH // 2 # Reset X position
|
||||
object_pos[1] = HEIGHT // 2 # Reset Y position
|
||||
|
||||
# Reset the sliders to the center position as well
|
||||
slider_x.set_value(WIDTH // 2)
|
||||
slider_y.set_value(HEIGHT // 2)
|
||||
|
||||
|
||||
# Update and display FPS
|
||||
fps_label.text = "FPS: " + str(round(clock.get_fps(), 1))
|
||||
position_label.text = "POS: " + str(object_pos)
|
||||
color_label.text = "COL: " + str(((20 * knob.angle/ 10), 255-(20 * knob.angle/ 10), 0))
|
||||
|
||||
color_label.text = "COL: " + str(((knob.angle), 255-(knob.angle), 0))
|
||||
|
||||
while True:
|
||||
screen.fill((30, 30, 30)) # Clear screen with a dark gray color
|
||||
screen.fill((0, 0, 0)) # Clear screen with a dark gray color
|
||||
|
||||
event_list = pygame.event.get()
|
||||
for event in event_list:
|
||||
@ -90,18 +100,13 @@ while True:
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_F3:
|
||||
DEBUG = not DEBUG
|
||||
|
||||
# Draw the object (rectangle)
|
||||
pygame.draw.rect(screen, ((20 * knob.angle/ 10), 255-(20 * knob.angle/ 10), 0), (*object_pos, *object_size))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pygame.draw.rect(screen, ((knob.angle), (255-knob.angle), 0), (*object_pos, *object_size))
|
||||
|
||||
# Draw the GUI
|
||||
if DEBUG:
|
||||
draw_gui()
|
||||
|
||||
pygame.display.flip()
|
||||
clock.tick()
|
||||
clock.tick(60)
|
||||
|
Loading…
Reference in New Issue
Block a user