ppizarror / pygame-menu

A menu for pygame. Simple, and easy to use
https://pygame-menu.readthedocs.io/
Other
544 stars 141 forks source link

Image onselect does not work #415

Closed enablex3 closed 2 years ago

enablex3 commented 2 years ago

Describe your environment information, such as:

Describe the bug When I click on the image I've added to my pygame menu, the function I've assigned to onselect does not get called

To Reproduce ` def set_ship(): global ship print("Clicked")

menu = pygame_menu.Menu('Main Menu', 500, 800, theme=pygame_menu.themes.THEME_DARK)

menu.add.selector('Difficulty: ', [('Easy', 1), ('Medium', 2), ('Hard', 3)], onchange=set_difficulty) menu.add.selector('Music: ', [('ON', 1), ('OFF', 0)], onchange=set_music) menu.add.selector('SFX: ', [('ON', 1), ('OFF', 0)], onchange=set_sfx) menu.add.button('Play', play_game) menu.add.button('Quit', pygame_menu.events.PYGAME_QUIT)

ships = settings["options"]["ships"] menu.add.image(ships["The Goblin"]["original_img"], onselect=set_ship)

menu.mainloop(WIN)`

Expected behavior The text "Clicked" is printed to the console

Additional context Add any other context about the problem here.

devfred78 commented 2 years ago

Hello, Did you try to use the selectable parameter in the menu.add.image() method ? In your example: menu.add.image(ships["The Goblin"]["original_img"], onselect=set_ship, selectable=True). I met the same issue, this parameter saved me :-) !

enablex3 commented 2 years ago

This worked! Thank you!

enablex3 commented 2 years ago

Hello, Did you try to use the selectable parameter in the menu.add.image() method ? In your example: menu.add.image(ships["The Goblin"]["original_img"], onselect=set_ship, selectable=True). I met the same issue, this parameter saved me :-) !

This worked! Thank you! Thank you!

ppizarror commented 2 years ago

Hey @devfred78 thanks for solving the issue :)

enablex3 commented 1 year ago

Wow ! That worked! Thank you!

On Sat, Jun 11, 2022 at 12:21 PM devfred78 @.***> wrote:

Hello, Did you try to use the selectable parameter in the menu.add.image() method ? In your example: menu.add.image(ships["The Goblin"]["original_img"], onselect=set_ship, selectable=True). I met the same issue, this parameter saved me :-) !

— Reply to this email directly, view it on GitHub https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fppizarror%2Fpygame-menu%2Fissues%2F415%23issuecomment-1152959090&data=05%7C01%7C%7C6ee6948325e8496379fc08da4bc673c0%7C960c1081d06341f8844b41d738db04a3%7C0%7C0%7C637905612965297083%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=85Big5j9Q5HQGg8pkLAKUb4hhKZ2OuF7ifXkrn%2BtY4Y%3D&reserved=0, or unsubscribe https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAJ73YH4JZFZXKZ5TR44JZS3VOS4I3ANCNFSM5X4OTYHA&data=05%7C01%7C%7C6ee6948325e8496379fc08da4bc673c0%7C960c1081d06341f8844b41d738db04a3%7C0%7C0%7C637905612965297083%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=cdQKnP1tSp%2Bd1GQIMjTdf8V447VAyU9vce%2Fydbk6leo%3D&reserved=0 . You are receiving this because you authored the thread.Message ID: @.***>