KivyToast#

Implementation of toasts for desktop.

from kivy.lang import Builder

from kivymd.app import MDApp
from kivymd.toast import toast

KV = '''
MDScreen:

    MDTopAppBar:
        title: 'Test Toast'
        pos_hint: {'top': 1}
        left_action_items: [['menu', lambda x: x]]

    MDRaisedButton:
        text: 'TEST KIVY TOAST'
        pos_hint: {'center_x': .5, 'center_y': .5}
        on_release: app.show_toast()
'''


class Test(MDApp):
    def show_toast(self):
        '''Displays a toast on the screen.'''

        toast('Test Kivy Toast')

    def build(self):
        return Builder.load_string(KV)

Test().run()

API - kivymd.toast.kivytoast.kivytoast#

class kivymd.toast.kivytoast.kivytoast.Toast(**kwargs)#

Base class for dialog movement behavior.

For more information, see in the MotionBase class documentation.

duration#

The amount of time (in seconds) that the toast is visible on the screen.

duration is an NumericProperty and defaults to 2.5.

label_check_texture_size(self, instance_label: Label, texture_size: List[int])#

Resizes the text if the text texture is larger than the screen size. Sets the size of the toast according to the texture size of the toast text.

toast(self, text_toast: str)#

Displays a toast.

on_open(self)#

Default open event handler.

fade_in(self)#

Animation of opening toast on the screen.

fade_out(self, *args)#

Animation of hiding toast on the screen.

on_touch_down(self, touch)#

touch down event handler.

kivymd.toast.kivytoast.kivytoast.toast(text: str = '', background: list = None, duration: float = 2.5) None#

Displays a toast.

Parameters:
  • text – text to be displayed in the toast;

  • duration – the amount of time (in seconds) that the toast is visible on the screen

  • background – toast background color in rgba format;