KivyToast¶
Implementation of toasts for desktop.
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.toast import toast
KV = '''
MDScreen:
MDToolbar:
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)¶
ModalView class. See module documentation for more information.
- Events
- on_pre_open:
Fired before the ModalView is opened. When this event is fired ModalView is not yet added to window.
- on_open:
Fired when the ModalView is opened.
- on_pre_dismiss:
Fired before the ModalView is closed.
- on_dismiss:
Fired when the ModalView is closed. If the callback returns True, the dismiss will be canceled.
Changed in version 1.11.0: Added events on_pre_open and on_pre_dismiss.
Changed in version 2.0.0: Added property ‘overlay_color’.
- duration¶
The amount of time (in seconds) that the toast is visible on the screen.
duration
is anNumericProperty
and defaults to 2.5.
- label_check_texture_size(self, instance, texture_size)¶
- toast(self, text_toast)¶
- on_open(self)¶
- fade_in(self)¶
- fade_out(self, *args)¶
- on_touch_down(self, touch)¶
Receive a touch down event.
- Parameters
- touch:
MotionEvent
class Touch received. The touch is in parent coordinates. See
relativelayout
for a discussion on coordinate systems.
- touch:
- Returns
bool If True, the dispatching of the touch event will stop. If False, the event will continue to be dispatched to the rest of the widget tree.
- kivymd.toast.kivytoast.kivytoast.toast(text='', background=[0.2, 0.2, 0.2, 1], duration=2.5)¶
Displays a toast.
- Attr duration
the amount of time (in seconds) that the toast is visible on the screen
- Attr background
color
rgba
in Kivy format