Adding a number to a variable in a while true loop once in python












2















I am calling a fucntion for a pygame so i need to have it in a loop and i want to add 50 to a variable called sy=100. The function reads a directory looking for any python files and if it finds them i want to display the first file at 100 which is the start point of sy. then i want to add 50 to the variable and then it write the next file at the next point without moving the first one so far it just writes the text all at the same point and moves it down the screen so how would i get it so each file is seperated by 50 pixels and the text doesn't move.



Heres my Function



def games():
f = 0
sy = 100
file =
ftext = pygame.font.SysFont("Arial", 20)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
screen.fill(DarkSpace)
ToolBarButton("Home", 0, 0, 150, 50, SpaceGrey, CornflowerBlue, 10, cmain)
ToolBarButton(username, 153,0,150,50, SpaceGrey, CornflowerBlue, 10, accountDetails)
ToolBarButton("Programs", 305,0,150,50, SpaceGrey, CornflowerBlue, 10, programs)
ToolBarButton("Games", 458,0,150,50, SpaceGrey, CornflowerBlue, 10, games)
ToolBarButton("Help", 610,0,150,50, SpaceGrey, CornflowerBlue, 10, hel)
DropDown(NeonGreen, CornflowerBlue, 764, 16, 30, 30, DropMenu)
Btext(screen, "Loading Games!", CornflowerBlue, ftext, 600,600,600,600)
fileDir = os.listdir("Games\")
for fileN in fileDir:
verif = fileN.endswith('.py') or fileN.endswith('.pyw')
if not verif:
fileDir.remove(fileN)
else:
text(screen, fileN, CornflowerBlue, ftext, 400,sy)


pygame.display.update()









share|improve this question



























    2















    I am calling a fucntion for a pygame so i need to have it in a loop and i want to add 50 to a variable called sy=100. The function reads a directory looking for any python files and if it finds them i want to display the first file at 100 which is the start point of sy. then i want to add 50 to the variable and then it write the next file at the next point without moving the first one so far it just writes the text all at the same point and moves it down the screen so how would i get it so each file is seperated by 50 pixels and the text doesn't move.



    Heres my Function



    def games():
    f = 0
    sy = 100
    file =
    ftext = pygame.font.SysFont("Arial", 20)
    while True:
    for event in pygame.event.get():
    if event.type == pygame.QUIT:
    pygame.quit()
    quit()
    screen.fill(DarkSpace)
    ToolBarButton("Home", 0, 0, 150, 50, SpaceGrey, CornflowerBlue, 10, cmain)
    ToolBarButton(username, 153,0,150,50, SpaceGrey, CornflowerBlue, 10, accountDetails)
    ToolBarButton("Programs", 305,0,150,50, SpaceGrey, CornflowerBlue, 10, programs)
    ToolBarButton("Games", 458,0,150,50, SpaceGrey, CornflowerBlue, 10, games)
    ToolBarButton("Help", 610,0,150,50, SpaceGrey, CornflowerBlue, 10, hel)
    DropDown(NeonGreen, CornflowerBlue, 764, 16, 30, 30, DropMenu)
    Btext(screen, "Loading Games!", CornflowerBlue, ftext, 600,600,600,600)
    fileDir = os.listdir("Games\")
    for fileN in fileDir:
    verif = fileN.endswith('.py') or fileN.endswith('.pyw')
    if not verif:
    fileDir.remove(fileN)
    else:
    text(screen, fileN, CornflowerBlue, ftext, 400,sy)


    pygame.display.update()









    share|improve this question

























      2












      2








      2








      I am calling a fucntion for a pygame so i need to have it in a loop and i want to add 50 to a variable called sy=100. The function reads a directory looking for any python files and if it finds them i want to display the first file at 100 which is the start point of sy. then i want to add 50 to the variable and then it write the next file at the next point without moving the first one so far it just writes the text all at the same point and moves it down the screen so how would i get it so each file is seperated by 50 pixels and the text doesn't move.



      Heres my Function



      def games():
      f = 0
      sy = 100
      file =
      ftext = pygame.font.SysFont("Arial", 20)
      while True:
      for event in pygame.event.get():
      if event.type == pygame.QUIT:
      pygame.quit()
      quit()
      screen.fill(DarkSpace)
      ToolBarButton("Home", 0, 0, 150, 50, SpaceGrey, CornflowerBlue, 10, cmain)
      ToolBarButton(username, 153,0,150,50, SpaceGrey, CornflowerBlue, 10, accountDetails)
      ToolBarButton("Programs", 305,0,150,50, SpaceGrey, CornflowerBlue, 10, programs)
      ToolBarButton("Games", 458,0,150,50, SpaceGrey, CornflowerBlue, 10, games)
      ToolBarButton("Help", 610,0,150,50, SpaceGrey, CornflowerBlue, 10, hel)
      DropDown(NeonGreen, CornflowerBlue, 764, 16, 30, 30, DropMenu)
      Btext(screen, "Loading Games!", CornflowerBlue, ftext, 600,600,600,600)
      fileDir = os.listdir("Games\")
      for fileN in fileDir:
      verif = fileN.endswith('.py') or fileN.endswith('.pyw')
      if not verif:
      fileDir.remove(fileN)
      else:
      text(screen, fileN, CornflowerBlue, ftext, 400,sy)


      pygame.display.update()









      share|improve this question














      I am calling a fucntion for a pygame so i need to have it in a loop and i want to add 50 to a variable called sy=100. The function reads a directory looking for any python files and if it finds them i want to display the first file at 100 which is the start point of sy. then i want to add 50 to the variable and then it write the next file at the next point without moving the first one so far it just writes the text all at the same point and moves it down the screen so how would i get it so each file is seperated by 50 pixels and the text doesn't move.



      Heres my Function



      def games():
      f = 0
      sy = 100
      file =
      ftext = pygame.font.SysFont("Arial", 20)
      while True:
      for event in pygame.event.get():
      if event.type == pygame.QUIT:
      pygame.quit()
      quit()
      screen.fill(DarkSpace)
      ToolBarButton("Home", 0, 0, 150, 50, SpaceGrey, CornflowerBlue, 10, cmain)
      ToolBarButton(username, 153,0,150,50, SpaceGrey, CornflowerBlue, 10, accountDetails)
      ToolBarButton("Programs", 305,0,150,50, SpaceGrey, CornflowerBlue, 10, programs)
      ToolBarButton("Games", 458,0,150,50, SpaceGrey, CornflowerBlue, 10, games)
      ToolBarButton("Help", 610,0,150,50, SpaceGrey, CornflowerBlue, 10, hel)
      DropDown(NeonGreen, CornflowerBlue, 764, 16, 30, 30, DropMenu)
      Btext(screen, "Loading Games!", CornflowerBlue, ftext, 600,600,600,600)
      fileDir = os.listdir("Games\")
      for fileN in fileDir:
      verif = fileN.endswith('.py') or fileN.endswith('.pyw')
      if not verif:
      fileDir.remove(fileN)
      else:
      text(screen, fileN, CornflowerBlue, ftext, 400,sy)


      pygame.display.update()






      python-3.x variables pygame






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 3:40









      DextronDextron

      427




      427
























          1 Answer
          1






          active

          oldest

          votes


















          0














          So i tried figuring it out and i did! So i add the filtered files to a list and then do another for loop to break them up and then i write them to the screen. I also took the part where i read the directory and filter it for certian files out of the loop to make it eaiser new function



          def games():
          file =
          ftext = pygame.font.SysFont("Arial", 20)
          fileDir = os.listdir("Games\")
          for fileN in fileDir:
          verif = fileN.endswith('.py') or fileN.endswith('.pyw')
          if not verif:
          fileDir.remove(fileN)
          else:
          file.append(fileN)
          while True:
          sy = 100
          for event in pygame.event.get():
          if event.type == pygame.QUIT:
          pygame.quit()
          quit()
          screen.fill(DarkSpace)
          ToolBarButton("Home", 0, 0, 150, 50, SpaceGrey, CornflowerBlue, 10, cmain)
          ToolBarButton(username, 153,0,150,50, SpaceGrey, CornflowerBlue, 10, accountDetails)
          ToolBarButton("Programs", 305,0,150,50, SpaceGrey, CornflowerBlue, 10, programs)
          ToolBarButton("Games", 458,0,150,50, SpaceGrey, CornflowerBlue, 10, games)
          ToolBarButton("Help", 610,0,150,50, SpaceGrey, CornflowerBlue, 10, hel)
          DropDown(NeonGreen, CornflowerBlue, 764, 16, 30, 30, DropMenu)
          for data in file:
          sy += 50
          text(screen, data, NeonGreen, ftext, 400,sy)
          pygame.display.update()


          If anyone has a btter way or a different solution please let me know!






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312093%2fadding-a-number-to-a-variable-in-a-while-true-loop-once-in-python%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            So i tried figuring it out and i did! So i add the filtered files to a list and then do another for loop to break them up and then i write them to the screen. I also took the part where i read the directory and filter it for certian files out of the loop to make it eaiser new function



            def games():
            file =
            ftext = pygame.font.SysFont("Arial", 20)
            fileDir = os.listdir("Games\")
            for fileN in fileDir:
            verif = fileN.endswith('.py') or fileN.endswith('.pyw')
            if not verif:
            fileDir.remove(fileN)
            else:
            file.append(fileN)
            while True:
            sy = 100
            for event in pygame.event.get():
            if event.type == pygame.QUIT:
            pygame.quit()
            quit()
            screen.fill(DarkSpace)
            ToolBarButton("Home", 0, 0, 150, 50, SpaceGrey, CornflowerBlue, 10, cmain)
            ToolBarButton(username, 153,0,150,50, SpaceGrey, CornflowerBlue, 10, accountDetails)
            ToolBarButton("Programs", 305,0,150,50, SpaceGrey, CornflowerBlue, 10, programs)
            ToolBarButton("Games", 458,0,150,50, SpaceGrey, CornflowerBlue, 10, games)
            ToolBarButton("Help", 610,0,150,50, SpaceGrey, CornflowerBlue, 10, hel)
            DropDown(NeonGreen, CornflowerBlue, 764, 16, 30, 30, DropMenu)
            for data in file:
            sy += 50
            text(screen, data, NeonGreen, ftext, 400,sy)
            pygame.display.update()


            If anyone has a btter way or a different solution please let me know!






            share|improve this answer




























              0














              So i tried figuring it out and i did! So i add the filtered files to a list and then do another for loop to break them up and then i write them to the screen. I also took the part where i read the directory and filter it for certian files out of the loop to make it eaiser new function



              def games():
              file =
              ftext = pygame.font.SysFont("Arial", 20)
              fileDir = os.listdir("Games\")
              for fileN in fileDir:
              verif = fileN.endswith('.py') or fileN.endswith('.pyw')
              if not verif:
              fileDir.remove(fileN)
              else:
              file.append(fileN)
              while True:
              sy = 100
              for event in pygame.event.get():
              if event.type == pygame.QUIT:
              pygame.quit()
              quit()
              screen.fill(DarkSpace)
              ToolBarButton("Home", 0, 0, 150, 50, SpaceGrey, CornflowerBlue, 10, cmain)
              ToolBarButton(username, 153,0,150,50, SpaceGrey, CornflowerBlue, 10, accountDetails)
              ToolBarButton("Programs", 305,0,150,50, SpaceGrey, CornflowerBlue, 10, programs)
              ToolBarButton("Games", 458,0,150,50, SpaceGrey, CornflowerBlue, 10, games)
              ToolBarButton("Help", 610,0,150,50, SpaceGrey, CornflowerBlue, 10, hel)
              DropDown(NeonGreen, CornflowerBlue, 764, 16, 30, 30, DropMenu)
              for data in file:
              sy += 50
              text(screen, data, NeonGreen, ftext, 400,sy)
              pygame.display.update()


              If anyone has a btter way or a different solution please let me know!






              share|improve this answer


























                0












                0








                0







                So i tried figuring it out and i did! So i add the filtered files to a list and then do another for loop to break them up and then i write them to the screen. I also took the part where i read the directory and filter it for certian files out of the loop to make it eaiser new function



                def games():
                file =
                ftext = pygame.font.SysFont("Arial", 20)
                fileDir = os.listdir("Games\")
                for fileN in fileDir:
                verif = fileN.endswith('.py') or fileN.endswith('.pyw')
                if not verif:
                fileDir.remove(fileN)
                else:
                file.append(fileN)
                while True:
                sy = 100
                for event in pygame.event.get():
                if event.type == pygame.QUIT:
                pygame.quit()
                quit()
                screen.fill(DarkSpace)
                ToolBarButton("Home", 0, 0, 150, 50, SpaceGrey, CornflowerBlue, 10, cmain)
                ToolBarButton(username, 153,0,150,50, SpaceGrey, CornflowerBlue, 10, accountDetails)
                ToolBarButton("Programs", 305,0,150,50, SpaceGrey, CornflowerBlue, 10, programs)
                ToolBarButton("Games", 458,0,150,50, SpaceGrey, CornflowerBlue, 10, games)
                ToolBarButton("Help", 610,0,150,50, SpaceGrey, CornflowerBlue, 10, hel)
                DropDown(NeonGreen, CornflowerBlue, 764, 16, 30, 30, DropMenu)
                for data in file:
                sy += 50
                text(screen, data, NeonGreen, ftext, 400,sy)
                pygame.display.update()


                If anyone has a btter way or a different solution please let me know!






                share|improve this answer













                So i tried figuring it out and i did! So i add the filtered files to a list and then do another for loop to break them up and then i write them to the screen. I also took the part where i read the directory and filter it for certian files out of the loop to make it eaiser new function



                def games():
                file =
                ftext = pygame.font.SysFont("Arial", 20)
                fileDir = os.listdir("Games\")
                for fileN in fileDir:
                verif = fileN.endswith('.py') or fileN.endswith('.pyw')
                if not verif:
                fileDir.remove(fileN)
                else:
                file.append(fileN)
                while True:
                sy = 100
                for event in pygame.event.get():
                if event.type == pygame.QUIT:
                pygame.quit()
                quit()
                screen.fill(DarkSpace)
                ToolBarButton("Home", 0, 0, 150, 50, SpaceGrey, CornflowerBlue, 10, cmain)
                ToolBarButton(username, 153,0,150,50, SpaceGrey, CornflowerBlue, 10, accountDetails)
                ToolBarButton("Programs", 305,0,150,50, SpaceGrey, CornflowerBlue, 10, programs)
                ToolBarButton("Games", 458,0,150,50, SpaceGrey, CornflowerBlue, 10, games)
                ToolBarButton("Help", 610,0,150,50, SpaceGrey, CornflowerBlue, 10, hel)
                DropDown(NeonGreen, CornflowerBlue, 764, 16, 30, 30, DropMenu)
                for data in file:
                sy += 50
                text(screen, data, NeonGreen, ftext, 400,sy)
                pygame.display.update()


                If anyone has a btter way or a different solution please let me know!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 6:39









                DextronDextron

                427




                427
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312093%2fadding-a-number-to-a-variable-in-a-while-true-loop-once-in-python%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown