title: Python/Pygame: How to make buttons scale on screen with amount of buttons and screen size?
body: <p>Basically i am writing a program that looks sort of like a control panel in python/pygame. Its purpose is to read a number of files with a certain file extension, count them, and then draw a number of buttons on the control panel according to the corresponding amount of files counted. </p>
  
  <p>I have achieved this, but my one problem is that i need to be able to make the buttons form in organized rows within the restrictions of the given screen. However, I am not quite sure how to approach this so i decided to try stackoverflow to see if anybody has been able to overcome this endeavor before.</p>
  
  <p>The code is as follows:</p>
  
  <pre><code>def Button_Build(gamesnum): # 'gamesnum' is the amount of detected files
      Screensize = 200 #size of given screen space
      button_size = Screensize/len(gamesnum) * 2   #Size of the button according to amount of files found/size of screen
      x = 9 #button's original x coordinate
      y = 20 #button's original y coordinate        
  
      butrow = 0  #Counter for how many buttons that can fit inside of the given screen space
      butmax = 0 #Maximum amount of buttons that can fit inside of given screen space
  
      for i in gamesnum: #Going through the number of files counted
          print(x) #Print the drawn buttons' x coordinate
  
          #If next button doesn't go out of given screen space
          if x &lt; Screensize - (Screensize/int(len(gamesnum))): 
              lebutton=GUI_Helper(white, red9, x, y)
              lebutton.Standard_button_make(button_size, button_size-2)
              x += (button_size + 2)
              butrow += 1
  
          #When maximum amount of buttons that can fit across the screen is reached
          if butrow == butmax: 
              butrow = 0 #Reset the counter
              x = 9 #Reset button's x coordinate
              y += (button_size + 2) #Move next buttons down a row
  
      pygame.display.update()    
  </code></pre>
  
  <p>So as you can see, i am still quite the amateur at programming and as such i truly apologize for how hard it may be to understand my code written above. If I need to clarify anything or answer any questions, let me know and i will do my best to answer them!</p>
  
  <p>Thanks in advance!</p>
  
  <p>~Dachua</p>