Quick snackbar

35 views
Skip to first unread message

coutinh...@gmail.com

unread,
May 15, 2022, 8:18:29 AM5/15/22
to Kivy users support
Hello friends.

I'm having some trouble with the snackbar.
They work, they appear as is in the kivymd demo, however they appear where they are not needed.

In the attached example I have the screen_lista.py file

In the on_enter event on line 111 of this file it should show the snackbar, the error is that it is showing the snackbar as soon as the application starts.

Any tips?

Elliot Garbus

unread,
May 15, 2022, 9:48:11 AM5/15/22
to kivy-...@googlegroups.com
Looks like you forgot to attach the file. 

Sent from my iPhone

On May 15, 2022, at 5:18 AM, coutinh...@gmail.com <coutinh...@gmail.com> wrote:

Hello friends.
--
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/c8bd4023-e806-4925-8a79-79ac0f480f34n%40googlegroups.com.

Elias Coutinho

unread,
May 16, 2022, 6:46:21 AM5/16/22
to kivy-...@googlegroups.com
Elliot, if you click on some points on the first screen, the snackbar appears, it should only appear in the list.



--
Elias Coutinho.
Aprender sobre alguns assuntos é fundamental.
Aprender sobre Deus é indiscutivelmente o melhor conteúdo.
snackbar.zip

Elliot Garbus

unread,
May 16, 2022, 10:43:52 AM5/16/22
to kivy-...@googlegroups.com

If the problem is you do not want to snackbar to be opened the first time the screen is entered, you can add a variable to track that.  See the example below.

 

class ScreenRecycleView(Screen):
    image_data = ListProperty()

   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)
       
self.first_view = True

    def
on_kv_post(self, base_widget):
       
self.ids.rv.data = [
            {
                
'source': choice(sample_images),
               
'text': ''.join(sample(ascii_lowercase, 6))

            }
           
for x in range(50)
        ]

   
def on_enter(self):
       
if self.first_view:
           
self.first_view = False
        else
:
            Snackbar(
text='Após a pesquisa clique 2x na imagem.').open()

Elias Coutinho

unread,
May 17, 2022, 6:59:55 PM5/17/22
to kivy-...@googlegroups.com
The problem is that I call the snackbar in the screen_lista file in the on_enter event, however on the login screen if I click anywhere other than a field it calls the snackbar incorrectly.

Elliot Garbus

unread,
May 17, 2022, 11:07:24 PM5/17/22
to kivy-...@googlegroups.com

I did not see this behavior.

Elias Coutinho

unread,
May 18, 2022, 7:51:47 AM5/18/22
to kivy-...@googlegroups.com
When the first screen appears, note that the snackbarr already appears, the correct thing would be to appear on the listing screen.

Captura de tela de 2022-05-18 08-50-01.png

Elliot Garbus

unread,
May 18, 2022, 5:04:28 PM5/18/22
to kivy-...@googlegroups.com

The on_enter event is firing in your nested screen manager, causing the snackbar to show up.  The snackbar is not attached to the screen so is displayed on the current screen.  Here is a possible workaround.

 

Add a screen to the nested screen_manager as a place holder.  This way the ScreenRecycleView will not be entered by default.

 


ScreenManager:
    id: screen_manager
    Screen:  # placeholder so ScreenRecycleView is not opened by default
    ScreenRecycleView:
    TelaLogin:
    TelaItem:

 

Then in your primary screen_manager, change to the ‘screen_listagem’ when entering the main screen.

ScreenManager:
    id: screen_manager_login

    TelaLogin:
        name: 'tela_login'

    MainScreen:
        name: 'main_screen'
        on_enter: self.ids.screen_manager.current = 'screen_listagem'              
'''

 

This should fix the behavior of the SnackBar.

 

Things might be simpler if you did not nest your ScreenManagers.  They are both taking the full screen – so I don’t understand the utility of nesting them.

Elias Coutinho

unread,
May 20, 2022, 6:32:12 PM5/20/22
to kivy-...@googlegroups.com
I think it's a bug, the problem continues.

Elliot Garbus

unread,
May 20, 2022, 7:22:28 PM5/20/22
to kivy-...@googlegroups.com
I don’t see buggy behavior. 

Sent from my iPhone

On May 20, 2022, at 3:32 PM, Elias Coutinho <coutinh...@gmail.com> wrote:


Reply all
Reply to author
Forward
0 new messages