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

开始

  • 什么是Arcade?
  • 从这里开始
  • 安装
    • 在Windows上安装
    • 在Mac上安装
    • 在Linux上安装
    • 从源安装
    • 在PyCharm中设置虚拟环境
    • 安装过时的Python版本
  • 如何获得帮助

实例

  • How-to示例代码
  • Python Discord GameJam2020
  • 用Arade制作的游戏

教程

  • 简单平台
    • 第1步-安装并打开窗口
    • 第2步-纹理和雪碧
    • 第3步-多款雪碧和SpriteList
    • 第4步-添加用户控件
    • 第5步-添加重力
    • 步骤6-重置
    • 第7步-添加摄像头
    • 第八步--收集硬币
    • 第9步-添加声音
    • 第10步-添加分数
    • 第11步-使用场景
    • 第12步-从地图编辑器加载地图
    • 第13步-更多类型的层
    • 第14步-多个级别
  • PyMunk平台
  • 使用开始/结束屏幕的视图
  • 单人纸牌
  • 电灯
  • 使用PyInstaller捆绑游戏
  • 使用Nuitka一起编译游戏
  • 着色器
    • 光线投射阴影
    • CRT滤光片
    • 着色器玩具-发光
    • 着色器玩具粒子
    • 计算着色器
    • GPU粒子爆发
    • 使用着色器
  • 用Arade的图形用户界面制作菜单
  • 使用FrameBuffer对象

导览

  • 绘制和使用精灵
    • 使用Sprite和SpriteList绘制
    • 高级SpriteList技术
  • 键盘
  • 声响
  • 纹理
  • 分段
  • GUI
    • 图形用户界面概念
    • 图形用户界面风格
    • 故障排除和提示
  • 纹理地图集
  • 边缘伪影
  • 日志记录
  • OpenGL
  • 性能
  • 无头Arcade
  • 垂直同步
  • 比较Pygame

API

  • Index
  • Reference
    • 类型
    • 绘图-基本体
    • 形状列表
    • 绘图-实用程序
    • 小精灵
    • 精灵列表
    • 精灵场景
    • 文本
    • 切片地图阅读器
    • 纹理管理
    • 纹理变换
    • 纹理地图集
    • 性能信息
    • 物理引擎
    • 其他实用程序功能
    • 几何图形支持
    • 游戏控制器支持
    • 操纵杆支撑
    • 窗口和视图
    • 声响
    • 寻路
    • 等轴测贴图支持(不完整)
    • 耳夹
    • 放松
    • OpenGL上下文
    • 数学
    • OpenGL
      • 语境
      • 纹理
      • 缓冲层
      • BufferDescription
      • 几何图形
      • 帧缓冲
      • 查询
      • 计划
      • 计算着色器
      • 例外情况
    • GUI
    • 图形用户界面小部件
    • 图形用户界面事件
    • 图形用户界面属性
    • 图形用户界面风格
    • 图形用户界面的实验特征
    • Arcade.key包
    • Arcade.css颜色包
    • Arcade.COLOR包
  • 内置资源

源代码

  • GitHub
  • 发行说明
  • 许可证
  • 为拱廊做出贡献
  • 发布检查清单

社交

  • 不和谐(最活跃的点)
  • Reddit/r/pythonarcade
  • 推特@ArcadeLibrary
  • 邮箱:Instagram@PythonArcadeLibrary
  • 邮箱:Facebook@ArcadeLibrary
  • 不同的编码者

学习资源

  • 书籍-学习使用Arade编程
  • 使用Arade和 Python Banyan进行点对点游戏
  • 美国PYCON 2022会谈
  • 美国PyCon 2019教程
  • 澳大利亚PYCON 2018年多人游戏
  • 2018年美国PYCON演讲
Back to top

MENU_05.py差异#

menu_05.py#
--- /pb1/repo/arcade/doc/tutorials/menu/menu_04.py
+++ /pb1/repo/arcade/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 © 2024, Paul Vincent Craven
Made with Sphinx and @pradyunsg's Furo