Tooltip#
#
See also
Tooltips display brief labels or messages.
Use tooltips to add additional context to a button or other UI element
Two types: plain and rich
Use plain tooltips to describe elements or actions of icon buttons
Use rich tooltips to provide more details, like describing the value of a feature
Rich tooltips can include an optional title, link, and buttons
KivyMD provides two types of tooltip:
Plain tooltip
Rich tooltip
Usage of tooltip plain#
from kivy.lang import Builder
from kivy.properties import StringProperty
from kivymd.uix.button import MDButton
from kivymd.uix.tooltip import MDTooltip
from kivymd.app import MDApp
KV = '''
<YourTooltipClass>
MDTooltipPlain:
text:
"Grant value is calculated using the closing stock price \\n" \
"from the day before the grant date. Amounts do not \\n" \
"reflect tax witholdings."
<TooltipMDIconButton>
MDButtonText:
text: root.text
MDScreen:
md_bg_color: self.theme_cls.backgroundColor
TooltipMDIconButton:
text: "Tooltip button"
pos_hint: {"center_x": .5, "center_y": .5}
'''
class YourTooltipClass(MDTooltip):
'''Implements your tooltip base class.'''
class TooltipMDIconButton(YourTooltipClass, MDButton):
'''Implements a button with tooltip behavior.'''
text = StringProperty()
class Example(MDApp):
def build(self):
self.theme_cls.primary_palette = "Olive"
return Builder.load_string(KV)
Example().run()
from kivy.properties import StringProperty
from kivy.clock import Clock
from kivymd.uix.button import MDButton, MDButtonText
from kivymd.uix.screen import MDScreen
from kivymd.uix.tooltip import MDTooltip, MDTooltipPlain
from kivymd.app import MDApp
class YourTooltipClass(MDTooltip):
'''Implements your tooltip base class.'''
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.widgets = [
MDTooltipPlain(
text="Grant value is calculated using the closing stock price
- “
“from the day before the grant date. Amounts do not
- “
“reflect tax witholdings.”,
)
]
- class TooltipMDIconButton(YourTooltipClass, MDButton):
‘’’Implements a button with tooltip behavior.’’’
text = StringProperty()
- class Example(MDApp):
- def build(self):
self.theme_cls.primary_palette = “Olive” return (
- MDScreen(
- TooltipMDIconButton(
text=”Tooltip button”, pos_hint={“center_x”: .5, “center_y”: .5},
), md_bg_color=self.theme_cls.backgroundColor,
)
)
Example().run()
The anatomy of a plain tooltip#
Usage of tooltip rich#
from kivy.lang import Builder
from kivy.properties import StringProperty
from kivymd.uix.button import MDButton
from kivymd.uix.tooltip import MDTooltip
from kivymd.app import MDApp
KV = '''
<YourTooltipClass>
MDTooltipRich:
id: tooltip
auto_dismiss: False
MDTooltipRichSubhead:
text: "Add others"
MDTooltipRichSupportingText:
text:
"Grant value is calculated using the closing stock price \\n" \
"from the day before the grant date. Amounts do not \\n" \
"reflect tax witholdings."
MDTooltipRichActionButton:
on_press: tooltip.dismiss()
MDButtonText:
text: "Learn more"
<TooltipMDIconButton>
MDButtonText:
text: root.text
MDScreen:
md_bg_color: self.theme_cls.backgroundColor
TooltipMDIconButton:
text: "Tooltip button"
pos_hint: {"center_x": .5, "center_y": .5}
'''
class YourTooltipClass(MDTooltip):
'''Implements your tooltip base class.'''
class TooltipMDIconButton(YourTooltipClass, MDButton):
'''Implements a button with tooltip behavior.'''
text = StringProperty()
class Example(MDApp):
def build(self):
self.theme_cls.primary_palette = "Olive"
return Builder.load_string(KV)
Example().run()
from kivy.properties import StringProperty
from kivy.clock import Clock
from kivymd.uix.button import MDButton, MDButtonText
from kivymd.uix.screen import MDScreen
from kivymd.uix.tooltip import (
MDTooltip,
MDTooltipRich,
MDTooltipRichSubhead,
MDTooltipRichSupportingText,
MDTooltipRichActionButton,
)
from kivymd.app import MDApp
class YourTooltipClass(MDTooltip):
'''Implements your tooltip base class.'''
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.widgets = [
MDTooltipRich(
MDTooltipRichSubhead(
text="Add others",
),
MDTooltipRichSupportingText(
text="Grant value is calculated using the closing stock price
- “
“from the day before the grant date. Amounts do not
- “
“reflect tax witholdings.”
), MDTooltipRichActionButton(
- MDButtonText(
text=”Learn more”,
), on_press=self.tooltip_dismiss,
), id=”tooltip”, auto_dismiss=False,
),
]
- def tooltip_dismiss(self, *args):
MDApp.get_running_app().root.get_ids().tooltip.dismiss()
- class TooltipMDIconButton(YourTooltipClass, MDButton):
‘’’Implements a button with tooltip behavior.’’’
text = StringProperty()
- class Example(MDApp):
- def build(self):
self.theme_cls.primary_palette = “Olive” return (
- MDScreen(
- TooltipMDIconButton(
text=”Tooltip button”, pos_hint={“center_x”: .5, “center_y”: .5},
), md_bg_color=self.theme_cls.backgroundColor,
)
)
Example().run()
The anatomy of a plain tooltip#
API - kivymd.uix.tooltip.tooltip#
- class kivymd.uix.tooltip.tooltip.MDTooltip(**kwargs)#
Tooltip class.
For more information, see in the
TouchBehaviorclass documentation.- Events:
- on_open:
Fired when the tooltip opens.
- on_dismiss:
Fired when the tooltip is closed.
- tooltip_display_delay#
Tooltip display delay.
Note
This property only works on desktop.
tooltip_display_delayis anBoundedNumericPropertyand defaults to 0, min of 0 & max of 4.
- shift_y#
Y-offset of tooltip to the top.
shift_yis anNumericPropertyand defaults to 0.
- shift_right#
Shifting the tooltip to the right.
Added in version 1.0.0.
shift_rightis anNumericPropertyand defaults to 0.
- shift_left#
Shifting the tooltip to the left.
Added in version 1.0.0.
shift_leftis anNumericPropertyand defaults to 0.
- delete_clock(widget, touch, *args)#
Removes a key event from touch.ud.
- adjust_tooltip_position() tuple#
Returns the coordinates of the tooltip that fit into the borders of the screen.
- animation_tooltip_dismiss(*args) None#
Animation of closing tooltip on the screen.
Added in version 1.0.0.
- add_widget(widget, *args, **kwargs)#
Add a new widget as a child of this widget.
- class kivymd.uix.tooltip.tooltip.MDTooltipPlain(*args, **kwargs)#
Tooltip plain class.
Added in version 2.0.0.
For more information, see in the
MDLabelandScaleBehaviorclasses documentation.
- class kivymd.uix.tooltip.tooltip.MDTooltipRichSupportingText(*args, **kwargs)#
Implements supporting text for the
MDTooltipRichclass.Added in version 2.0.0.
For more information, see in the
MDLabelclass documentation.
- class kivymd.uix.tooltip.tooltip.MDTooltipRichSubhead(*args, **kwargs)#
Implements subhead text for the
MDTooltipRichclass.Added in version 2.0.0.
For more information, see in the
MDLabelclass documentation.
- class kivymd.uix.tooltip.tooltip.MDTooltipRichActionButton(*args, **kwargs)#
Implements action button for the
MDTooltipRichclass.Added in version 2.0.0.
For more information, see in the
MDButtonclass documentation.
- class kivymd.uix.tooltip.tooltip.MDTooltipRich(*args, **kwargs)#
Tooltip rich class.
Added in version 2.0.0.
For more information, see in the
DeclarativeBehaviorandThemableBehaviorandBackgroundColorBehaviorandCommonElevationBehaviorandScaleBehaviorandStateLayerBehaviorandBoxLayoutand classes documentation.- auto_dismiss#
This property determines if the view is automatically dismissed when the cursor goes outside of the tooltip body.
auto_dismissis aBooleanPropertyand defaults to True.