I am having trouble understanding how to create a clickable button that can be clicked with a mouse. Although I've looked at some posts about it, I'm still confused. Could someone please explain to me a clear explanation?
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/media/38029/2_Picotron 2024_05_12 0_22_57.png)
I'm not sure if my explanation makes sense, but using a table like an object-oriented class will save you time and effort.
This "pseudo-class" remembers the button positions and text, and has an update "method" that reacts when the mouse enters or the button is pressed.
In _init() I created two buttons in a new table using the "pseudo-class".
In _draw() I call the update method for each button.
Give it a try :)
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/media/92447/Logo.png)
You should look into the gui library that comes built into picotron!
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](https://www.lexaloffle.com/bbs/files/32759/comovic.gif)
Since I cannot judge your programming proficiency, I will give you a brief description.
If you have difficulty with the objective, try to break down what you are creating.
- Obtain mouse input.
- Use
mouse()
to get the x/y of the coordinates, and the state of the button.
- Use
- Determine that you clicked.
- use
print()
to check the button status
- use
- Create the area of the button.
- For the rectangle used in picotron, it may be useful to have variables for the Start x/y and End x/y coordinates to draw and determine the button's state.
- Draw the button.
- Use the
rect()
function.
- Use the
If you can create these one by one, you are pretty close to what you want.
https://www.lexaloffle.com/dl/docs/picotron_manual.html
Check the manual for details on how to use the functions.
Since picotron is still in alpha version, you may encounter specification changes or unstable situations.
Nevertheless, I am enjoying this world.
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/bimg/pi/pi7.png)
Thank you everyone. I am now closer to understanding Picotron.
[Please log in to post a comment]