Wiki 9Minecraft Wiki 9Minecraft
Improperui Wiki › Guides › Add Interactivity with Buttons and Event Handlers

Add Interactivity with Buttons and Event Handlers

Creating Interactive Buttons

Buttons are one of the most common interactive elements. Define a button element in your UI script and assign it a unique id so you can reference it in code.

Linking Events to Actions

1. Create a button element with text content and styling

2. In your mod code, register an event callback that listens for clicks on that button's ID

3. Inside the callback function, execute whatever action you want (open a menu, toggle a setting, send a command)

4. Use the ImproperUI API's element query methods to find your button by ID

5. Attach the callback to the button's click event

Testing Your Button

Load into a world and hover over your button to confirm it responds to mouse movement. Click it and verify your callback executes. You can chain multiple buttons together, each with different callbacks, to build complex menus.

For visual feedback, consider changing the button's background color or text when hovered. ImproperUI supports pseudo-states like :hover, making it easy to create responsive button designs without extra code.