Here is the Code I am on.
Popup works for the first time when the Button '1' is clicked but If I click again on the button I get an error
'kivy.uix.widget.WidgetException: Cannot add <__main__.ButtonOne object at 0x03B04AE8>, it already has a parent <kivy.uix.boxlayout.BoxLayout object at 0x068CD228>'
I don't know why is this happening anyone could explain me this,It would be appreciable.
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.scrollview import ScrollView
from kivy.uix.popup import Popup
Builder.load_string('''
<MyApp>:
BoxLayout:
orientation:'horizontal'
GridLayout:
cols:1
padding:20
spacing:20
TextInput:
id:search_key
size_hint:1,None
height:50
multiline:False
spacing:20
on_text_validate:root.d()
Button:
BoxLayout:
orientation:'vertical'
ScrollView:
size_hint:1,1
GridLayout:
size_hint:1,None
height:self.minimum_height
cols:1
BoxLayout:
size_hint:1,None
height:500
orientation:'vertical'
Button:
size_hint:1,.7
text:'1'
on_press:app.get_image()
GridLayout:
size_hint:1,.3
cols:3
Button:
Button:
Button:
Button:
size_hint:1,None
height:500
Button:
size_hint:1,None
height:500
''')
class ButtonOne(Button):
pass
class CustomPopup(Popup):
from kivy.uix.button import Button
b=ButtonOne()
def __init__(self,**kwargs):
super(CustomPopup,self).__init__(**kwargs)
self.size_hint=[.5,.5]
self.auto_dismiss=False
self.title='That\'s the title'
self.b.text="Just a button"
self.b.bind(on_release=self.dism)
self.content=self.b
def dism(self,*args):
self.dismiss()
class MyApp(BoxLayout):
def d(self):
print 'lost focus'
pass
class Main(App):
def build(self):
return MyApp()
def get_image(self):
c=CustomPopup()
c.open()
Main().run()