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

                              Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                              Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                              Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved