Python Forum
Problems with loading buttons (pygame)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems with loading buttons (pygame)
#2
i do see the buttons, but they are completely unresponsive and even not rendering every frame. You have a lot of poor programming practices in this one piece of code. If i fixed your code to work, i would completely have to rewrite it. Fixing it to just work now is setting you up for failure in t he future.

1)There should only ever be one line in your code of
pygame.display.update()
and it should reside in your main game loop. The fact that you have more than one is a sign that you are creating your structure incorrectly and you are making spaghetti code. As a result the code is not working correctly and is really hard to fix. The more that is added, the worse it gets.

2) There is a reason we use classes. Buttons are complex enough that it is much simpler to handle them in classes. As a bonus you wont have confusing 11 parameters to one function anymore.

3) You are creating and running the button in the middle of the main game loop. The buttons should be created beforehand, and only update and draw methods should be in the main game loop.

Here are some links that i would suggest to read thoroughly.
state machine
user interface
classes
Recommended Tutorials:
Reply


Messages In This Thread
RE: Problems with loading buttons (pygame) - by metulburr - Apr-12-2019, 02:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pygame installation problems Gheryk 5 8,629 Nov-29-2023, 08:49 PM
Last Post: E_Mohamed
  [PyGame] pygame-manu : using controller buttons to move around menu mlw19mlw91 2 1,631 Mar-12-2023, 01:55 PM
Last Post: deanhystad
  [PyGame] Problems with jump code in pygame Joningstone 4 5,378 Aug-23-2021, 08:23 PM
Last Post: deanhystad
  Pygame - Images As Buttons vman44 3 13,010 Mar-20-2020, 08:13 PM
Last Post: vman44
  [PyGame] pygame image loading error BlueClaw 6 6,412 Dec-10-2019, 08:50 PM
Last Post: BlueClaw
  [Pygame] Problems with my textbox SheeppOSU 1 3,089 May-27-2019, 12:03 AM
Last Post: metulburr
  [pygame] Inventory problems. Weapons equipped to wrong slot SheeppOSU 6 4,028 May-07-2019, 02:46 AM
Last Post: SheeppOSU
  [pygame] Equiping inventory slots with invisible buttons SheeppOSU 6 4,736 Apr-26-2019, 08:45 PM
Last Post: SheeppOSU
  drawing, moving, and collision problems (pygame) SheeppOSU 26 14,733 Apr-22-2019, 03:09 AM
Last Post: SheeppOSU
  Buttons in PyGame mzmingle 4 13,067 Oct-09-2018, 05:19 PM
Last Post: Mekire

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020