Все еще учусь использовать Kivy и сейчас сталкиваюсь с проблемой создания кнопки закрытия для всплывающего окна. Предназначен для реализации в kv-файле и из do c, я знаю, что скрипт on_release = root .dismiss (). Но не знаю, почему продолжайте говорить «AttributeError: у объекта PricePopup нет атрибута« dismiss »»
Python file
class AmazonFront(Widget):
asin = ObjectProperty(None)
country = ObjectProperty(None)
def submit_button(self):
item = Item(self.asin)
item.add_country(self.country)
item_info(item)
def popup_price(self):
show_pricePopup(self.asin.text)
class PricePopup(FloatLayout):
name = StringProperty()
pass
def show_pricePopup(ASIN):
show = PricePopup()
store = JsonStore('Price.json')
show.name = str(store.get(ASIN)['name'])
popupWindow = Popup(title="Popup Window", content=show, size_hint=(None, None), size=(400, 400))
popupWindow.open()
class AmazonApp(App):
def build(self):
return AmazonFront()
if __name__ == "__main__":
AmazonApp().run()
kv file
<AmazonFront>
asin: Asin
country: cn
GridLayout:
cols: 1
size: root.width-200, root.height-200
pos: 100,100
GridLayout:
cols : 2
Label:
text: "ASIN"
TextInput:
id: Asin
multinline : False
Label:
text: "Amazon Country"
TextInput:
id: cn
multinline :False
Button:
text: "Submit"
on_press: root.submit_button()
on_press: root.popup_price()
<PricePopup>
Label:
text: "Name: {}".format(root.name)
size_hint: 0.6, 0.2
pos_hint: {"x":0.2, "top":1}
Button:
text: "Close"
on_press: root.dismiss()