Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions arcade/examples/gui_ok_messagebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,24 @@ def __init__(self):
self.v_box = arcade.gui.widgets.layout.UIBoxLayout()

# Create a button. We'll click on this to open our window.
# Add it v_box for positioning.
open_message_box_button = arcade.gui.widgets.buttons.UIFlatButton(
text="Open", width=200
show_message_box_button = arcade.gui.widgets.buttons.UIFlatButton(
text="Show Message Box", width=300
)
self.v_box.add(open_message_box_button)
# Create a label to show the user's choices
self.last_choice = arcade.gui.UILabel(
text="",
align="left", width=300
)

# Add both widgets to the v_box to center them
self.v_box.add(show_message_box_button)
self.v_box.add(self.last_choice)

# Add a hook to run when we click on the button.
open_message_box_button.on_click = self.on_click_open
self.open_message_box_button = open_message_box_button
# Create a widget to hold the v_box widget, that will center the buttons
show_message_box_button.on_click = self.on_click_open
self.open_message_box_button = show_message_box_button

# Create a widget to hold the v_box widget, that will center the buttons
ui_anchor_layout = arcade.gui.widgets.layout.UIAnchorLayout()
ui_anchor_layout.add(child=self.v_box, anchor_x="center_x", anchor_y="center_y")
self.ui.add(ui_anchor_layout)
Expand All @@ -44,15 +51,16 @@ def on_click_open(self, _: UIOnClickEvent):
width=300,
height=200,
message_text=(
"You should have a look on the new GUI features "
"coming up with arcade 2.6!"
"Which option do you choose?"
),
buttons=["Ok", "Cancel"],
)

@message_box.event("on_action")
def on_message_box_close(e: UIOnActionEvent):
print(f"User pressed {e.action}.")
# Update the last_choice display
self.last_choice.text = f"User pressed {e.action}."
self.last_choice.fit_content() # Important! Update the layout!

# show open button and allow interaction again
self.open_message_box_button.visible = True
Expand All @@ -75,9 +83,6 @@ def on_draw(self):
self.clear()
self.ui.draw()

def on_key_release(self, symbol: int, modifiers: int):
print(self.open_message_box_button.rect)


if __name__ == '__main__':
window = arcade.Window(800, 600, "UIExample", resizable=True)
Expand Down
Binary file modified doc/example_code/how_to_examples/gui_ok_messagebox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.