Contents Menu Expand Light mode Dark mode Auto light/dark mode
Python Arcade 3.0.0.dev26
Light Logo Dark Logo
Python Arcade 3.0.0.dev26

Get Started

  • What is Arcade?
  • Start Here
  • Installation
    • Installation on Windows
    • Installation on Mac
    • Installation on Linux
    • Installation From Source
    • Setting Up a Virtual Environment In PyCharm
    • Installation for Obsolete Python Versions
  • How to Get Help

Examples

  • How-To Example Code
  • Python Discord GameJam 2020
  • Games Made With Arcade

Tutorials

  • Simple Platformer
    • Step 1 - Install and Open a Window
    • Step 2 - Add Sprites
    • Step 3 - Scene Object
    • Step 4 - Add User Control
    • Step 5 - Add Gravity
    • Step 6 - Add a Camera
    • Step 7 - Add Coins And Sound
    • Step 8 - Display The Score
    • Step 9 - Use Tiled Map Editor
    • Step 10 - Multiple Levels and Other Layers
    • Step 11 - Add Ladders, Properties, and a Moving Platform
    • Step 12 - Add Character Animations, and Better Keyboard Control
    • Step 13 - Add Enemies
    • Step 14 - Moving Enemies
    • Step 15 - Collision with Enemies
    • Step 16 - Shooting Bullets
    • Step 17 - Views
  • Pymunk Platformer
  • Using Views for Start/End Screens
  • Solitaire
  • Lights
  • Bundling a Game with PyInstaller
  • Compiling a Game with Nuitka
  • Shaders
    • Ray-casting Shadows
    • CRT Filter
    • Shader Toy - Glow
    • Shader Toy - Particles
    • Compute Shader
    • GPU Particle Burst
    • Working With Shaders
  • Making a Menu with Arcade’s GUI
  • Working With FrameBuffer Objects

Guide

  • Drawing & Using Sprites
    • What’s a Sprite?
    • Why SpriteLists?
    • Drawing with Sprites and SpriteLists
    • Advanced SpriteList Techniques
  • Keyboard
  • Sound
  • Textures
  • Sections
  • GUI
    • GUI Concepts
    • GUI Style
    • Troubleshooting & Hints
  • Texture Atlas
  • Edge Artifacts
  • Logging
  • OpenGL
  • Performance
  • Headless Arcade
  • Vertical Synchronization
  • Pygame Comparison

API

  • Index
  • Reference
    • Types
    • Drawing - Primitives
    • Shape Lists
    • Drawing - Utility
    • Sprites
    • Sprite Lists
    • Sprite Scenes
    • Camera
    • Text
    • Tiled Map Reader
    • Texture Management
    • Texture Transforms
    • Texture Atlas
    • Performance Information
    • Physics Engines
    • Misc Utility Functions
    • Geometry Support
    • Game Controller Support
    • Joystick Support
    • Window and View
    • Sound
    • Pathfinding
    • Isometric Map Support (incomplete)
    • Earclip
    • Easing
    • OpenGL Context
    • Math
    • OpenGL
      • Context
      • Texture
      • Buffer
      • BufferDescription
      • Geometry
      • Framebuffer
      • Query
      • Program
      • Compute Shader
      • Exceptions
    • GUI
    • GUI Widgets
    • GUI Events
    • GUI Properties
    • GUI Style
    • arcade.key package
    • arcade.csscolor package
    • arcade.color package
  • Built-In Resources

Source Code

  • GitHub
  • Release Notes
  • License

Contributing

  • Ways to Contribute
  • Contributing to Arcade
  • Directory Structure
  • How to Submit Changes
  • Release Checklist
  v: development
Versions
latest
stable
2.6.17
2.6.16
2.6.15
2.6.14
2.6.13
2.6.12
2.6.11
2.6.10
2.6.9
2.6.8
2.6.7
2.6.6
2.6.5
2.6.4
2.6.3
2.6.2
2.6.1
2.6.0
2.5.7
platformer_tutorial_revamp
doc_structural_improvements
development
Downloads
pdf
epub
On Read the Docs
Project Home
Builds
Back to top
Edit this page

menu_05.py Diff#

menu_05.py#
--- /home/docs/checkouts/readthedocs.org/user_builds/arcade-library/checkouts/development/doc/tutorials/menu/menu_04.py
+++ /home/docs/checkouts/readthedocs.org/user_builds/arcade-library/checkouts/development/doc/tutorials/menu/menu_05.py
@@ -3,6 +3,8 @@
 
 Shows the usage of almost every gui widget, switching views and making a modal.
 """
+from typing import List
+
 import arcade
 import arcade.gui
 
@@ -110,7 +112,11 @@
 
         @volume_button.event("on_click")
         def on_click_volume_button(event):
-            volume_menu = SubMenu()
+            volume_menu = SubMenu(
+                "Volume Menu", "How do you like your volume?", "Enable Sound",
+                ["Play: Rock", "Play: Punk", "Play: Pop"],
+                "Adjust Volume",
+            )
             self.manager.add(
                 volume_menu,
                 layer=1
@@ -118,7 +124,11 @@
 
         @options_button.event("on_click")
         def on_click_options_button(event):
-            options_menu = SubMenu()
+            options_menu = SubMenu(
+                "Funny Menu", "Too much fun here", "Fun?",
+                ["Make Fun", "Enjoy Fun", "Like Fun"],
+                "Adjust Fun",
+            )
             self.manager.add(
                 options_menu,
                 layer=1
@@ -147,7 +157,7 @@
 class SubMenu(arcade.gui.UIMouseFilterMixin, arcade.gui.UIAnchorLayout):
     """Acts like a fake view/window."""
 
-    def __init__(self, ):
+    def __init__(self, title: str, input_text: str, toggle_label: str, dropdown_options: List[str], slider_label: str):
         super().__init__(size_hint=(1, 1))
 
         # Setup frame which will act like the window.
@@ -155,6 +165,7 @@
         frame.with_padding(all=20)
 
         # Add a background to the window.
+        # Nine patch smoothes the edges.
         frame.with_background(texture=arcade.gui.NinePatchTexture(
             left=7,
             right=7,
@@ -169,8 +180,48 @@
         # The type of event listener we used earlier for the button will not work here.
         back_button.on_click = self.on_click_back_button
 
-        # Internal widget layout to handle widgets in this class.
+        title_label = arcade.gui.UILabel(text=title, align="center", font_size=20, multiline=False)
+        # Adding some extra space around the title.
+        title_label_space = arcade.gui.UISpace(height=30, color=arcade.color.DARK_BLUE_GRAY)
+
+        input_text_widget = arcade.gui.UIInputText(text=input_text, width=250).with_border()
+
+        # Load the on-off textures.
+        on_texture = arcade.load_texture(":resources:gui_basic_assets/toggle/circle_switch_on.png")
+        off_texture = arcade.load_texture(":resources:gui_basic_assets/toggle/circle_switch_off.png")
+
+        # Create the on-off toggle and a label
+        toggle_label = arcade.gui.UILabel(text=toggle_label)
+        toggle = arcade.gui.UITextureToggle(
+            on_texture=on_texture,
+            off_texture=off_texture,
+            width=20,
+            height=20
+        )
+
+        # Align toggle and label horizontally next to each other
+        toggle_group = arcade.gui.UIBoxLayout(vertical=False, space_between=5)
+        toggle_group.add(toggle)
+        toggle_group.add(toggle_label)
+
+        # Create dropdown with a specified default.
+        dropdown = arcade.gui.UIDropdown(default=dropdown_options[0], options=dropdown_options, height=20, width=250)
+
+        slider_label = arcade.gui.UILabel(text=slider_label)
+        pressed_style = arcade.gui.UISlider.UIStyle(filled_bar=arcade.color.GREEN, unfilled_bar=arcade.color.RED)
+        default_style = arcade.gui.UISlider.UIStyle()
+        style_dict = {"press": pressed_style, "normal": default_style, "hover": default_style, "disabled": default_style}
+        # Configuring the styles is optional.
+        slider = arcade.gui.UISlider(value=50, width=250, style=style_dict)
+
         widget_layout = arcade.gui.UIBoxLayout(align="left", space_between=10)
+        widget_layout.add(title_label)
+        widget_layout.add(title_label_space)
+        widget_layout.add(input_text_widget)
+        widget_layout.add(toggle_group)
+        widget_layout.add(dropdown)
+        widget_layout.add(slider_label)
+        widget_layout.add(slider)
 
         widget_layout.add(back_button)
 
Copyright © 2023, Paul Vincent Craven
Made with Sphinx and @pradyunsg's Furo