Skip to content

Instantly share code, notes, and snippets.

@ppizarror
Created March 10, 2023 21:18
Show Gist options
  • Save ppizarror/57b4a690093545edfbe1edb7ea540c02 to your computer and use it in GitHub Desktop.
Save ppizarror/57b4a690093545edfbe1edb7ea540c02 to your computer and use it in GitHub Desktop.
Scrollable table within pygame menu using frames
import pygame
import pygame_menu
pygame.init()
surface = pygame.display.set_mode((600, 400))
# Create theme
theme = pygame_menu.themes.THEME_DARK.copy()
theme.title_font_size = 30
theme.title_bar_style = pygame_menu.widgets.MENUBAR_STYLE_SIMPLE
theme.widget_font_color = '#000000'
theme.widget_font_size = 20
# Create menu
menu = pygame_menu.Menu('Table within scrollable frame', 500, 300, theme=theme)
# Add a scrollable frame
frame = menu.add.frame_v(350, 730, max_height=150)
# Now, create a table
table_contrib = menu.add.table(font_size=10)
table_contrib.default_cell_padding = 5
table_contrib.default_row_background_color = 'white'
bold_font = pygame_menu.font.FONT_OPEN_SANS_BOLD
table_contrib.add_row(['N°', 'Github User'], cell_font=bold_font)
for i in range(len(pygame_menu.__contributors__)):
table_contrib.add_row([i + 1, pygame_menu.__contributors__[i]], cell_font=bold_font if i == 0 else None)
table_contrib.update_cell_style(-1, -1, font_size=15) # Update all column/row
table_contrib.update_cell_style(1, [2, -1], font=pygame_menu.font.FONT_OPEN_SANS_ITALIC)
# Add table to the frame
frame.pack(table_contrib, align=pygame_menu.locals.ALIGN_CENTER)
# Add another frame which contain two buttons
menu.add.vertical_margin(30)
frame_button = menu.add.frame_h(300, 50)
frame_button.pack(menu.add.button('Quit', pygame_menu.events.EXIT))
frame_button.pack(menu.add.horizontal_margin(70))
frame_button.pack(menu.add.button('Another button', pygame_menu.events.EXIT))
menu.mainloop(surface)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment