How to bind all frame widgets to event












-1















I the following code I want to bind all frame1 items to <'Enter'> Event, but it does not work. I mean canvas.focus_set() does not take effect. How can I solve my problem?



for w in frame1.winfo_children():
w.bind('<Enter>',canvas1.focus_set())









share|improve this question


















  • 2





    stackoverflow.com/questions/21225198/… OR stackoverflow.com/questions/17205852/…

    – Lafexlos
    Nov 27 '18 at 14:40











  • Also you might want to check bind_all method

    – Lafexlos
    Nov 27 '18 at 14:40











  • I checked all of your solutions but the problem exists again. My question is how to bind all frame items like check buttons to the same function event.

    – A.Keshavarz
    Nov 27 '18 at 14:57






  • 1





    bind method needs method itself (callback method) not its return value.

    – Lafexlos
    Nov 27 '18 at 15:00


















-1















I the following code I want to bind all frame1 items to <'Enter'> Event, but it does not work. I mean canvas.focus_set() does not take effect. How can I solve my problem?



for w in frame1.winfo_children():
w.bind('<Enter>',canvas1.focus_set())









share|improve this question


















  • 2





    stackoverflow.com/questions/21225198/… OR stackoverflow.com/questions/17205852/…

    – Lafexlos
    Nov 27 '18 at 14:40











  • Also you might want to check bind_all method

    – Lafexlos
    Nov 27 '18 at 14:40











  • I checked all of your solutions but the problem exists again. My question is how to bind all frame items like check buttons to the same function event.

    – A.Keshavarz
    Nov 27 '18 at 14:57






  • 1





    bind method needs method itself (callback method) not its return value.

    – Lafexlos
    Nov 27 '18 at 15:00
















-1












-1








-1








I the following code I want to bind all frame1 items to <'Enter'> Event, but it does not work. I mean canvas.focus_set() does not take effect. How can I solve my problem?



for w in frame1.winfo_children():
w.bind('<Enter>',canvas1.focus_set())









share|improve this question














I the following code I want to bind all frame1 items to <'Enter'> Event, but it does not work. I mean canvas.focus_set() does not take effect. How can I solve my problem?



for w in frame1.winfo_children():
w.bind('<Enter>',canvas1.focus_set())






python tkinter binding frame






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 27 '18 at 14:24









A.KeshavarzA.Keshavarz

105




105








  • 2





    stackoverflow.com/questions/21225198/… OR stackoverflow.com/questions/17205852/…

    – Lafexlos
    Nov 27 '18 at 14:40











  • Also you might want to check bind_all method

    – Lafexlos
    Nov 27 '18 at 14:40











  • I checked all of your solutions but the problem exists again. My question is how to bind all frame items like check buttons to the same function event.

    – A.Keshavarz
    Nov 27 '18 at 14:57






  • 1





    bind method needs method itself (callback method) not its return value.

    – Lafexlos
    Nov 27 '18 at 15:00
















  • 2





    stackoverflow.com/questions/21225198/… OR stackoverflow.com/questions/17205852/…

    – Lafexlos
    Nov 27 '18 at 14:40











  • Also you might want to check bind_all method

    – Lafexlos
    Nov 27 '18 at 14:40











  • I checked all of your solutions but the problem exists again. My question is how to bind all frame items like check buttons to the same function event.

    – A.Keshavarz
    Nov 27 '18 at 14:57






  • 1





    bind method needs method itself (callback method) not its return value.

    – Lafexlos
    Nov 27 '18 at 15:00










2




2





stackoverflow.com/questions/21225198/… OR stackoverflow.com/questions/17205852/…

– Lafexlos
Nov 27 '18 at 14:40





stackoverflow.com/questions/21225198/… OR stackoverflow.com/questions/17205852/…

– Lafexlos
Nov 27 '18 at 14:40













Also you might want to check bind_all method

– Lafexlos
Nov 27 '18 at 14:40





Also you might want to check bind_all method

– Lafexlos
Nov 27 '18 at 14:40













I checked all of your solutions but the problem exists again. My question is how to bind all frame items like check buttons to the same function event.

– A.Keshavarz
Nov 27 '18 at 14:57





I checked all of your solutions but the problem exists again. My question is how to bind all frame items like check buttons to the same function event.

– A.Keshavarz
Nov 27 '18 at 14:57




1




1





bind method needs method itself (callback method) not its return value.

– Lafexlos
Nov 27 '18 at 15:00







bind method needs method itself (callback method) not its return value.

– Lafexlos
Nov 27 '18 at 15:00














3 Answers
3






active

oldest

votes


















1














The comment made by Lafexlos actually sends you in the right direction. When you do



w.bind('<Enter>', canvas1.focus_set())


you call canvas1.focus_set() and use the return value of this function call (which is None) to bind to the event. This isn't what you want, because now every time the event is triggered, None is executed instead of canvas1.focus_set().



What you should do is pass a function reference to the bind function. The reference for calling canvas1.focus_set() is canvas1.focus_set. However, using



w.bind('<Enter>', canvas1.focus_set)


still doesn't work.

This is because the bind function passes an event object to the function it has been given, so it will call canvas1.focus_set(event) instead of canvas1.focus_set(). Because focus_set does not accept any arguments, this fails.



You can fix this in two ways. You could make an extra function, which does accept an event object and then calls canvas1.focus_set() without arguments, and then bind the event to this new function. The other option is to use an anonymous "lambda" function to basically do the same like



w.bind('<Enter>', lambda e: canvas1.focus_set())


This way the lambda function accepts the event object as e, but doesn't pass it to focus_set.





P.S. The <Enter> event is not the event that is triggered when you press the Enter button on your keyboard (that is <Return>). The <Enter> event is triggered whenever you move the mouse onto a widget and is accompanied by the <Leave> event for when you leave the widget with your mouse. This might be what you want, but it often leads to confusion.






share|improve this answer































    0














    by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.






    share|improve this answer































      -2














      If there is any mistake I see you making it is likely you are not calling the write command for the Enter key. Hopefully, if you are attempting to do this on windows, you should rather use Return.



      More like:



      for w in frame1.winfo_children():
      w.bind('<Return>',canvas1.focus_set())





      share|improve this answer
























      • Why the downvote? does Enter work on your own windows machine? uh?

        – Chuck G
        Nov 27 '18 at 15:15













      • I used Return key but it did not work again

        – A.Keshavarz
        Nov 27 '18 at 15:21











      • Use Return and rather than focus_set() you should bind to a function you created as stated earlier by @Lafexlos

        – Chuck G
        Nov 27 '18 at 15:43













      • <Enter> actually is a valid event and is fired whenever you enter a widget with your mouse. You're right in that <Return> is the event for pressing the Enter button, but whether that is or is not what the OP wants isn't clear from the question.

        – fhdrsdg
        Nov 27 '18 at 15:46











      • by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.

        – A.Keshavarz
        Nov 27 '18 at 16:46











      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%2f53501843%2fhow-to-bind-all-frame-widgets-to-enter-event%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      The comment made by Lafexlos actually sends you in the right direction. When you do



      w.bind('<Enter>', canvas1.focus_set())


      you call canvas1.focus_set() and use the return value of this function call (which is None) to bind to the event. This isn't what you want, because now every time the event is triggered, None is executed instead of canvas1.focus_set().



      What you should do is pass a function reference to the bind function. The reference for calling canvas1.focus_set() is canvas1.focus_set. However, using



      w.bind('<Enter>', canvas1.focus_set)


      still doesn't work.

      This is because the bind function passes an event object to the function it has been given, so it will call canvas1.focus_set(event) instead of canvas1.focus_set(). Because focus_set does not accept any arguments, this fails.



      You can fix this in two ways. You could make an extra function, which does accept an event object and then calls canvas1.focus_set() without arguments, and then bind the event to this new function. The other option is to use an anonymous "lambda" function to basically do the same like



      w.bind('<Enter>', lambda e: canvas1.focus_set())


      This way the lambda function accepts the event object as e, but doesn't pass it to focus_set.





      P.S. The <Enter> event is not the event that is triggered when you press the Enter button on your keyboard (that is <Return>). The <Enter> event is triggered whenever you move the mouse onto a widget and is accompanied by the <Leave> event for when you leave the widget with your mouse. This might be what you want, but it often leads to confusion.






      share|improve this answer




























        1














        The comment made by Lafexlos actually sends you in the right direction. When you do



        w.bind('<Enter>', canvas1.focus_set())


        you call canvas1.focus_set() and use the return value of this function call (which is None) to bind to the event. This isn't what you want, because now every time the event is triggered, None is executed instead of canvas1.focus_set().



        What you should do is pass a function reference to the bind function. The reference for calling canvas1.focus_set() is canvas1.focus_set. However, using



        w.bind('<Enter>', canvas1.focus_set)


        still doesn't work.

        This is because the bind function passes an event object to the function it has been given, so it will call canvas1.focus_set(event) instead of canvas1.focus_set(). Because focus_set does not accept any arguments, this fails.



        You can fix this in two ways. You could make an extra function, which does accept an event object and then calls canvas1.focus_set() without arguments, and then bind the event to this new function. The other option is to use an anonymous "lambda" function to basically do the same like



        w.bind('<Enter>', lambda e: canvas1.focus_set())


        This way the lambda function accepts the event object as e, but doesn't pass it to focus_set.





        P.S. The <Enter> event is not the event that is triggered when you press the Enter button on your keyboard (that is <Return>). The <Enter> event is triggered whenever you move the mouse onto a widget and is accompanied by the <Leave> event for when you leave the widget with your mouse. This might be what you want, but it often leads to confusion.






        share|improve this answer


























          1












          1








          1







          The comment made by Lafexlos actually sends you in the right direction. When you do



          w.bind('<Enter>', canvas1.focus_set())


          you call canvas1.focus_set() and use the return value of this function call (which is None) to bind to the event. This isn't what you want, because now every time the event is triggered, None is executed instead of canvas1.focus_set().



          What you should do is pass a function reference to the bind function. The reference for calling canvas1.focus_set() is canvas1.focus_set. However, using



          w.bind('<Enter>', canvas1.focus_set)


          still doesn't work.

          This is because the bind function passes an event object to the function it has been given, so it will call canvas1.focus_set(event) instead of canvas1.focus_set(). Because focus_set does not accept any arguments, this fails.



          You can fix this in two ways. You could make an extra function, which does accept an event object and then calls canvas1.focus_set() without arguments, and then bind the event to this new function. The other option is to use an anonymous "lambda" function to basically do the same like



          w.bind('<Enter>', lambda e: canvas1.focus_set())


          This way the lambda function accepts the event object as e, but doesn't pass it to focus_set.





          P.S. The <Enter> event is not the event that is triggered when you press the Enter button on your keyboard (that is <Return>). The <Enter> event is triggered whenever you move the mouse onto a widget and is accompanied by the <Leave> event for when you leave the widget with your mouse. This might be what you want, but it often leads to confusion.






          share|improve this answer













          The comment made by Lafexlos actually sends you in the right direction. When you do



          w.bind('<Enter>', canvas1.focus_set())


          you call canvas1.focus_set() and use the return value of this function call (which is None) to bind to the event. This isn't what you want, because now every time the event is triggered, None is executed instead of canvas1.focus_set().



          What you should do is pass a function reference to the bind function. The reference for calling canvas1.focus_set() is canvas1.focus_set. However, using



          w.bind('<Enter>', canvas1.focus_set)


          still doesn't work.

          This is because the bind function passes an event object to the function it has been given, so it will call canvas1.focus_set(event) instead of canvas1.focus_set(). Because focus_set does not accept any arguments, this fails.



          You can fix this in two ways. You could make an extra function, which does accept an event object and then calls canvas1.focus_set() without arguments, and then bind the event to this new function. The other option is to use an anonymous "lambda" function to basically do the same like



          w.bind('<Enter>', lambda e: canvas1.focus_set())


          This way the lambda function accepts the event object as e, but doesn't pass it to focus_set.





          P.S. The <Enter> event is not the event that is triggered when you press the Enter button on your keyboard (that is <Return>). The <Enter> event is triggered whenever you move the mouse onto a widget and is accompanied by the <Leave> event for when you leave the widget with your mouse. This might be what you want, but it often leads to confusion.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 27 '18 at 15:58









          fhdrsdgfhdrsdg

          7,11621837




          7,11621837

























              0














              by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.






              share|improve this answer




























                0














                by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.






                share|improve this answer


























                  0












                  0








                  0







                  by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.






                  share|improve this answer













                  by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 27 '18 at 16:48









                  A.KeshavarzA.Keshavarz

                  105




                  105























                      -2














                      If there is any mistake I see you making it is likely you are not calling the write command for the Enter key. Hopefully, if you are attempting to do this on windows, you should rather use Return.



                      More like:



                      for w in frame1.winfo_children():
                      w.bind('<Return>',canvas1.focus_set())





                      share|improve this answer
























                      • Why the downvote? does Enter work on your own windows machine? uh?

                        – Chuck G
                        Nov 27 '18 at 15:15













                      • I used Return key but it did not work again

                        – A.Keshavarz
                        Nov 27 '18 at 15:21











                      • Use Return and rather than focus_set() you should bind to a function you created as stated earlier by @Lafexlos

                        – Chuck G
                        Nov 27 '18 at 15:43













                      • <Enter> actually is a valid event and is fired whenever you enter a widget with your mouse. You're right in that <Return> is the event for pressing the Enter button, but whether that is or is not what the OP wants isn't clear from the question.

                        – fhdrsdg
                        Nov 27 '18 at 15:46











                      • by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.

                        – A.Keshavarz
                        Nov 27 '18 at 16:46
















                      -2














                      If there is any mistake I see you making it is likely you are not calling the write command for the Enter key. Hopefully, if you are attempting to do this on windows, you should rather use Return.



                      More like:



                      for w in frame1.winfo_children():
                      w.bind('<Return>',canvas1.focus_set())





                      share|improve this answer
























                      • Why the downvote? does Enter work on your own windows machine? uh?

                        – Chuck G
                        Nov 27 '18 at 15:15













                      • I used Return key but it did not work again

                        – A.Keshavarz
                        Nov 27 '18 at 15:21











                      • Use Return and rather than focus_set() you should bind to a function you created as stated earlier by @Lafexlos

                        – Chuck G
                        Nov 27 '18 at 15:43













                      • <Enter> actually is a valid event and is fired whenever you enter a widget with your mouse. You're right in that <Return> is the event for pressing the Enter button, but whether that is or is not what the OP wants isn't clear from the question.

                        – fhdrsdg
                        Nov 27 '18 at 15:46











                      • by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.

                        – A.Keshavarz
                        Nov 27 '18 at 16:46














                      -2












                      -2








                      -2







                      If there is any mistake I see you making it is likely you are not calling the write command for the Enter key. Hopefully, if you are attempting to do this on windows, you should rather use Return.



                      More like:



                      for w in frame1.winfo_children():
                      w.bind('<Return>',canvas1.focus_set())





                      share|improve this answer













                      If there is any mistake I see you making it is likely you are not calling the write command for the Enter key. Hopefully, if you are attempting to do this on windows, you should rather use Return.



                      More like:



                      for w in frame1.winfo_children():
                      w.bind('<Return>',canvas1.focus_set())






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 27 '18 at 15:10









                      Chuck GChuck G

                      13419




                      13419













                      • Why the downvote? does Enter work on your own windows machine? uh?

                        – Chuck G
                        Nov 27 '18 at 15:15













                      • I used Return key but it did not work again

                        – A.Keshavarz
                        Nov 27 '18 at 15:21











                      • Use Return and rather than focus_set() you should bind to a function you created as stated earlier by @Lafexlos

                        – Chuck G
                        Nov 27 '18 at 15:43













                      • <Enter> actually is a valid event and is fired whenever you enter a widget with your mouse. You're right in that <Return> is the event for pressing the Enter button, but whether that is or is not what the OP wants isn't clear from the question.

                        – fhdrsdg
                        Nov 27 '18 at 15:46











                      • by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.

                        – A.Keshavarz
                        Nov 27 '18 at 16:46



















                      • Why the downvote? does Enter work on your own windows machine? uh?

                        – Chuck G
                        Nov 27 '18 at 15:15













                      • I used Return key but it did not work again

                        – A.Keshavarz
                        Nov 27 '18 at 15:21











                      • Use Return and rather than focus_set() you should bind to a function you created as stated earlier by @Lafexlos

                        – Chuck G
                        Nov 27 '18 at 15:43













                      • <Enter> actually is a valid event and is fired whenever you enter a widget with your mouse. You're right in that <Return> is the event for pressing the Enter button, but whether that is or is not what the OP wants isn't clear from the question.

                        – fhdrsdg
                        Nov 27 '18 at 15:46











                      • by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.

                        – A.Keshavarz
                        Nov 27 '18 at 16:46

















                      Why the downvote? does Enter work on your own windows machine? uh?

                      – Chuck G
                      Nov 27 '18 at 15:15







                      Why the downvote? does Enter work on your own windows machine? uh?

                      – Chuck G
                      Nov 27 '18 at 15:15















                      I used Return key but it did not work again

                      – A.Keshavarz
                      Nov 27 '18 at 15:21





                      I used Return key but it did not work again

                      – A.Keshavarz
                      Nov 27 '18 at 15:21













                      Use Return and rather than focus_set() you should bind to a function you created as stated earlier by @Lafexlos

                      – Chuck G
                      Nov 27 '18 at 15:43







                      Use Return and rather than focus_set() you should bind to a function you created as stated earlier by @Lafexlos

                      – Chuck G
                      Nov 27 '18 at 15:43















                      <Enter> actually is a valid event and is fired whenever you enter a widget with your mouse. You're right in that <Return> is the event for pressing the Enter button, but whether that is or is not what the OP wants isn't clear from the question.

                      – fhdrsdg
                      Nov 27 '18 at 15:46





                      <Enter> actually is a valid event and is fired whenever you enter a widget with your mouse. You're right in that <Return> is the event for pressing the Enter button, but whether that is or is not what the OP wants isn't clear from the question.

                      – fhdrsdg
                      Nov 27 '18 at 15:46













                      by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.

                      – A.Keshavarz
                      Nov 27 '18 at 16:46





                      by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.

                      – A.Keshavarz
                      Nov 27 '18 at 16:46


















                      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%2f53501843%2fhow-to-bind-all-frame-widgets-to-enter-event%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

                      Contact image not getting when fetch all contact list from iPhone by CNContact

                      count number of partitions of a set with n elements into k subsets

                      A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks