how to define a series of buttons and run a function with a different input for each of them tkinter pythonGenerate Tkinter buttons dynamicallyWhat is the difference between range and xrange functions in Python 2.X?How do you test that a Python function throws an exception?How to get a function name as a string in Python?How do I detect whether a Python variable is a function?How do I check what version of Python is running my script?python open built-in function: difference between modes a, a+, w, w+, and r+?How to make a Python script standalone executable to run without ANY dependency?How to define a two-dimensional array in PythonWhy does Python code run faster in a function?How to change the text of the last clicked button in tkinter python

How should I respond when I lied about my education and the company finds out through background check?

How do you make your own symbol when Detexify fails?

How does a computer interpret real numbers?

Temporarily disable WLAN internet access for children, but allow it for adults

Lowest total scrabble score

Does the Linux kernel need a file system to run?

Multiplicative persistence

Extract more than nine arguments that occur periodically in a sentence to use in macros in order to typset

Can the US President recognize Israel’s sovereignty over the Golan Heights for the USA or does that need an act of Congress?

Can a Canadian Travel to the USA twice, less than 180 days each time?

Yosemite Fire Rings - What to Expect?

Is there an injective, monotonically increasing, strictly concave function from the reals, to the reals?

Using substitution ciphers to generate new alphabets in a novel

Why is the "ls" command showing permissions of files in a FAT32 partition?

How to hide some fields of struct in C?

On a tidally locked planet, would time be quantized?

Why is this estimator biased?

What does chmod -u do?

Can disgust be a key component of horror?

A social experiment. What is the worst that can happen?

Does Doodling or Improvising on the Piano Have Any Benefits?

Non-trope happy ending?

Why does the Sun have different day lengths, but not the gas giants?

Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?



how to define a series of buttons and run a function with a different input for each of them tkinter python


Generate Tkinter buttons dynamicallyWhat is the difference between range and xrange functions in Python 2.X?How do you test that a Python function throws an exception?How to get a function name as a string in Python?How do I detect whether a Python variable is a function?How do I check what version of Python is running my script?python open built-in function: difference between modes a, a+, w, w+, and r+?How to make a Python script standalone executable to run without ANY dependency?How to define a two-dimensional array in PythonWhy does Python code run faster in a function?How to change the text of the last clicked button in tkinter python













0















So I use a for-loop to define a series of buttons:



buy = [None] * 11
for x in range(11):
buy[x] = Button(buyf, text = ProjectList[x][2],command= lambda: buycheck(x), bg = "red", fg = "white")


Why when I press any of the buttons do they just return the maximum value(11)?
I want each of the buttons to call the function buycheck with the input of the x value at the time of assignment of said button. Also, the buttons are put into a pre-sized array and then referenced on and off.










share|improve this question




























    0















    So I use a for-loop to define a series of buttons:



    buy = [None] * 11
    for x in range(11):
    buy[x] = Button(buyf, text = ProjectList[x][2],command= lambda: buycheck(x), bg = "red", fg = "white")


    Why when I press any of the buttons do they just return the maximum value(11)?
    I want each of the buttons to call the function buycheck with the input of the x value at the time of assignment of said button. Also, the buttons are put into a pre-sized array and then referenced on and off.










    share|improve this question


























      0












      0








      0








      So I use a for-loop to define a series of buttons:



      buy = [None] * 11
      for x in range(11):
      buy[x] = Button(buyf, text = ProjectList[x][2],command= lambda: buycheck(x), bg = "red", fg = "white")


      Why when I press any of the buttons do they just return the maximum value(11)?
      I want each of the buttons to call the function buycheck with the input of the x value at the time of assignment of said button. Also, the buttons are put into a pre-sized array and then referenced on and off.










      share|improve this question
















      So I use a for-loop to define a series of buttons:



      buy = [None] * 11
      for x in range(11):
      buy[x] = Button(buyf, text = ProjectList[x][2],command= lambda: buycheck(x), bg = "red", fg = "white")


      Why when I press any of the buttons do they just return the maximum value(11)?
      I want each of the buttons to call the function buycheck with the input of the x value at the time of assignment of said button. Also, the buttons are put into a pre-sized array and then referenced on and off.







      python for-loop button tkinter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 6:55









      Fabricio Ceciliano

      245




      245










      asked Mar 7 at 6:37









      biddlsbiddls

      65




      65






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Take a look to Generate Tkinter buttons dynamically, according to what you said (which is not completely clear) you're having some trouble using dynamic buttons.






          share|improve this answer






























            0














            It is because buycheck(x) will always be executed with x = 10 (value after the for loop). You should pass x as default value of first argument of the lambda as below:



            command=lambda n=x: buycheck(n)





            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%2f55037512%2fhow-to-define-a-series-of-buttons-and-run-a-function-with-a-different-input-for%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              Take a look to Generate Tkinter buttons dynamically, according to what you said (which is not completely clear) you're having some trouble using dynamic buttons.






              share|improve this answer



























                0














                Take a look to Generate Tkinter buttons dynamically, according to what you said (which is not completely clear) you're having some trouble using dynamic buttons.






                share|improve this answer

























                  0












                  0








                  0







                  Take a look to Generate Tkinter buttons dynamically, according to what you said (which is not completely clear) you're having some trouble using dynamic buttons.






                  share|improve this answer













                  Take a look to Generate Tkinter buttons dynamically, according to what you said (which is not completely clear) you're having some trouble using dynamic buttons.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 7 at 6:45









                  Fabricio CecilianoFabricio Ceciliano

                  245




                  245























                      0














                      It is because buycheck(x) will always be executed with x = 10 (value after the for loop). You should pass x as default value of first argument of the lambda as below:



                      command=lambda n=x: buycheck(n)





                      share|improve this answer



























                        0














                        It is because buycheck(x) will always be executed with x = 10 (value after the for loop). You should pass x as default value of first argument of the lambda as below:



                        command=lambda n=x: buycheck(n)





                        share|improve this answer

























                          0












                          0








                          0







                          It is because buycheck(x) will always be executed with x = 10 (value after the for loop). You should pass x as default value of first argument of the lambda as below:



                          command=lambda n=x: buycheck(n)





                          share|improve this answer













                          It is because buycheck(x) will always be executed with x = 10 (value after the for loop). You should pass x as default value of first argument of the lambda as below:



                          command=lambda n=x: buycheck(n)






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 7 at 6:48









                          acw1668acw1668

                          2,6602716




                          2,6602716



























                              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%2f55037512%2fhow-to-define-a-series-of-buttons-and-run-a-function-with-a-different-input-for%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







                              Popular posts from this blog

                              1928 у кіно

                              Захаров Федір Захарович

                              Ель Греко