How to bind all frame widgets to event
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
add a comment |
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
2
stackoverflow.com/questions/21225198/… OR stackoverflow.com/questions/17205852/…
– Lafexlos
Nov 27 '18 at 14:40
Also you might want to checkbind_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
add a comment |
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
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
python tkinter binding frame
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 checkbind_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
add a comment |
2
stackoverflow.com/questions/21225198/… OR stackoverflow.com/questions/17205852/…
– Lafexlos
Nov 27 '18 at 14:40
Also you might want to checkbind_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
add a comment |
3 Answers
3
active
oldest
votes
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.
add a comment |
by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.
add a comment |
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())
Why the downvote? doesEnter
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
UseReturn
and rather thanfocus_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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 27 '18 at 15:58
fhdrsdgfhdrsdg
7,11621837
7,11621837
add a comment |
add a comment |
by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.
add a comment |
by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.
add a comment |
by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.
by using canvas1.bind_all which is the parent of frame1 I solved my problem. Thanks for all solutions.
answered Nov 27 '18 at 16:48
A.KeshavarzA.Keshavarz
105
105
add a comment |
add a comment |
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())
Why the downvote? doesEnter
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
UseReturn
and rather thanfocus_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
add a comment |
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())
Why the downvote? doesEnter
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
UseReturn
and rather thanfocus_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
add a comment |
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())
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())
answered Nov 27 '18 at 15:10
Chuck GChuck G
13419
13419
Why the downvote? doesEnter
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
UseReturn
and rather thanfocus_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
add a comment |
Why the downvote? doesEnter
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
UseReturn
and rather thanfocus_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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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