Show runtime errors on a popup window

106 views
Skip to first unread message

rajarame...@gmail.com

unread,
Feb 22, 2021, 6:41:33 AM2/22/21
to Kivy users support
Hi,

how to show runtime errors on  a popup window which are dynamic . 

Thanks,
Raja 

Elliot Garbus

unread,
Feb 22, 2021, 4:31:38 PM2/22/21
to kivy-...@googlegroups.com

I’m not sure I understand your question, but here is an example of a popup that takes a message at runtime.  I use something similar for errors.

 

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.popup import Popup
from kivy.properties import StringProperty

kv =
"""
#:import Factory kivy.factory.Factory
<ErrorPopup>:
    title: 'Error'
    BoxLayout:
        orientation: 'vertical'
        Label:
            text: root.error_msg
        Button:
            size_hint_y: None
            height: 48
            text: 'Okay'
            on_release: root.dismiss()

BoxLayout:
    orientation: 'vertical'
    Button:
        text: 'Press Error Popup 1'
        on_release: Factory.ErrorPopup(error_msg='Error Message Number One').open()
    Button:
        text: 'Press Error Popup 2'
        on_release:Factory.ErrorPopup(error_msg='A non-fatal error has occurred').open()
    Button:
        text: 'Press Error Popup 3'
        on_release: Factory.ErrorPopup(error_msg='You lose, your get nothing!').open()
    Button:
        text: 'Press Error Popup 4, from python'
        on_release: app.error('Oh My, somthing has happened here!')  
"""


class ErrorPopup(Popup):
    error_msg = StringProperty()


class ErrorPopApp(App):
   
def build(self):
       
return Builder.load_string(kv)

   
def error(self, text):
        ErrorPopup(
error_msg=text).open()


ErrorPopApp().run()

--
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/ed9c9c1e-8999-4506-99db-b2d305894755n%40googlegroups.com.

 

Raja Ramesh

unread,
Feb 23, 2021, 2:24:38 AM2/23/21
to kivy-...@googlegroups.com
Hi Elliot,

I am able to show a popup message from python code (code attached)based on the number entered in TextInput. But i am getting error when i try to  show a popup message from kivy file as below,

<WrongPopup>:
title: ''
separator_height: 0
size_hint:(None, None)
size:(350, 150)
auto_dismiss: False
BoxLayout:
orientation: 'vertical'
Label:
text: app.root.ids.sm.get_screen('Screen_1').ids.ti.text + 'is wrong guess...Try again!'
FloatLayout:
#orientation:'horizontal'
#size_hint_y:None
#height:30
#spacing: 10
Button:
text:'Yes'
size_hint: .2,.5
pos_hint:{'x':.4, 'y':.3}
on_press: root.dismiss()
Button:
text:'No'
size_hint: .2,.5
pos_hint:{'x':.6, 'y':.3}
on_press: app.stop()

RootBox:
ScreenManager:
id: sm
HomeScreen:
Screen1:
Screen2:
'''

Thanks,
Raja

raja_1.zip

Elliot Garbus

unread,
Feb 23, 2021, 8:55:58 AM2/23/21
to kivy-...@googlegroups.com

If you want to instance a popup in kv, use Factory as I did in the example I posted previously.  Note that Factory was imported into kv

Reply all
Reply to author
Forward
0 new messages