Reputation: 8297
I have several tkinter Entry
and Combobox
widgets that I can use the Tab
key to change focus from one widget to another. However, when the focus arrives at the last widget, the focus remains at the last widget and does not continue back to the first widget when Tab
is pressed. How can i get this continuation in the switching of focus?
Upvotes: 0
Views: 222
Reputation: 8297
I discovered the reasons to my issue:
I had created several
FrameButton widgets
before creating the Entry widgets and Combobox widget. By default,
these FrameButtons had takefocus=True
option defined.
These Framebuttons
, being a ttk
type widget, were created using a
custom style layout such that it only had padding
and label
elements. That is, it did not have a focus
element.
Hence when the Tab
key was pressed after the Combobox widget, focus had indeed move to the Framebutons. But because these FrameButtons
did not consist a focus element, the focus on these buttons could not be seen. And because there were many such buttons and the Combobox fieldbackground was selected after focus had left it, the effects of pressing the Tab
key felt as it focus had stopped at the Combobox. To visualise focus
in the FrameButtons
, I only had to ensure these button widgets had a focus
layout element like so:
buttonlayout =[('Button.focus', {'sticky': 'nswe', 'children':
[('Button.padding', {'sticky':'nswe', 'children':
[('Button.label', {'sticky': 'nswe'})]})]})]
s.layout('my.TButton', buttonlayout)
Summary:
Tab
keypress will cycle through all widgets defined
with option takefocus=True
in the order in which they are created.Upvotes: 0