Advertisement
Guest User

Kivy app confirm exit

a guest
Nov 11th, 2016
2,244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. from kivy.config import Config
  2. Config.set('kivy', 'exit_on_escape', '0')
  3.  
  4. from kivy.app import App
  5. from kivy.uix.label import Label
  6. from kivy.uix.boxlayout import BoxLayout
  7. from kivy.uix.button import Button
  8. from kivy.uix.popup import Popup
  9. from kivy.core.window import Window
  10.  
  11.  
  12. class ChildApp(App):
  13.  
  14.     def build(self):
  15.         Window.bind(on_request_close=self.on_request_close)
  16.         return Label(text='Child')
  17.  
  18.     def on_request_close(self, *args):
  19.         self.textpopup(title='Exit', text='Are you sure?')
  20.         return True
  21.  
  22.     def textpopup(self, title='', text=''):
  23.         """Open the pop-up with the name.
  24.  
  25.         :param title: title of the pop-up to open
  26.         :type title: str
  27.         :param text: main text of the pop-up to open
  28.         :type text: str
  29.         :rtype: None
  30.         """
  31.         box = BoxLayout(orientation='vertical')
  32.         box.add_widget(Label(text=text))
  33.         mybutton = Button(text='OK', size_hint=(1, 0.25))
  34.         box.add_widget(mybutton)
  35.         popup = Popup(title=title, content=box, size_hint=(None, None), size=(600, 300))
  36.         mybutton.bind(on_release=self.stop)
  37.         popup.open()
  38.  
  39.  
  40. if __name__ == '__main__':
  41.     ChildApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement