Hey, I am trying to make game in python and am currently stuck on trying to use buttons.
Here is an example of what I mean:
--Working code--
Code:
#!/usr/bin/python
import raydium
import sys
#this function would do something when button is pressed
def button():
print "Doing something.."
def create_gui():
#load theme
raydium.raydium_gui_theme_load("raydium_chat.gui")
#create gui window
handle=raydium.raydium_gui_window_create("menu",30,30,30,15)
#create a button
#link it to the function button()
#this is the problem, if you call just "button" then it errors
#if you call just "button()" then it calls button() at startup but never when it is clicked
raydium.raydium_gui_button_create("login",handle,30,30,"Login",button())
#raydium.raydium_gui_button_create("login",handle,30,30,"Login",button)
def display():
#start menu
if raydium.cvar.raydium_key_last==1027:
raydium.exit(0)
raydium.raydium_clear_frame()
raydium.raydium_rendering_finish();
raydium.raydium_init_args(sys.argv);
raydium.raydium_window_create(640,480,raydium.RAYDIUM_RENDERING_WINDOW,"Button test");
raydium.raydium_window_view_update();
#setup gui
create_gui()
raydium.raydium_gui_show()
raydium.SetMainLoopPython(display);
as you can see the function button() will be called when button is clicked, however it only calls at startup and never once button is clicked.
if you make the line:
raydium.raydium_gui_button_create("login",handle,30,30,"Login",button)
instead of:
raydium.raydium_gui_button_create("login",handle,30,30,"Login",button())
it will error with this:
Traceback (most recent call last):
File "test.py", line 38, in <module>
create_gui()
File "test.py", line 23, in create_gui
raydium.raydium_gui_button_create("login",handle,30,30,"Login",button)
TypeError: in method 'raydium_gui_button_create', argument 6 of type 'void *'
So question is, am I doing something wrong? how do I fix it?
Thanks!