You almost have it.
The behavior mixin must come first in the inheritance list. From the docs, “The behavior class must always be _before_ the widget class. If you don’t specify the inheritance in this order, the behavior will not work because the behavior methods are overwritten by the class method listed first.”
class FocusButton(FocusBehavior, Button):
pass
Adding an event to the FocusButton…
KV = '''
BoxLayout:
orientation: "vertical"
size_hint: .65, .65
pos_hint: {'center_x': 0.5,'center_y': 0.5}
padding: dp(48)
spacing: dp(20)
TextInput:
id: in1
hint_text: " First Input"
multiline: False
write_tab: False
TextInput:
id: in2
hint_text: " Second Input"
height: self.minimum_height
multiline: False
write_tab: False
focus_next: but3
#on_text_validate: but3.focus = True
FocusButton:
id: but3
text: "Get Focus"
on_focus: print(f'{self} has focus {self.focus}')
'''
You can see that the FocusButton gets focus. There is no default behavior for a button in focus. You will need to decide how you want the button to appear when in focus. You could add an outline using the canvas or change the background color, or bold the text…
I suspect you will also want the button to fire when the user presses Enter. You will also need to use the keyboard and add this to the Button.
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b0e660cb-cb64-4348-a0bc-ac5fdcc0f337n%40googlegroups.com.
Perfect!
Thank you very much ElliotG!
Exactly the information I was looking for.
> I suspect you will also want the button to fire when the user presses Enter. You will also need to use the keyboard and add this to the Button.
That is exactly what I should have asked. : )
However you have pointed me in the right direction.
Best Regards,
John.