Fairly new to kivy and only have a highschool education of python and have been stuck on this for a week now. I want a system where i can add and remove buttons in the StackLayout, how would i go about doing that?
I can add and remove the buttons I now just need to figure out how to place them in the correct area.
I understand this question is a bit of a clusterf*** and i have jumped in the deep end with this but i figured best was to learn is to dive right in to it.
pythton code:
# import kivy & functions/widgets.
import kivy
from kivy.app import App
from kivy.uix.button import Button
# import kivy layouts.
from kivy.uix.floatlayout import FloatLayout
# Specify version of kivy needed.
kivy.require("1.10.1")
# define buttons and widgets
testButton = Button(width=177, height=254, size_hint=(None, None), background_normal="pics/32864.jpg")
class Page(FloatLayout):
def __init__(self):
super().__init__()
def add_button(self):
Page.add_widget(self, widget=testButton)
class YuGiOhApp(App):
pass
YuGiOhApp().run()
My .kv code:
#:kivy 1.10.1
<[email protected]>:
width: 177
height: 254
size_hint: None, None
background_normal: "pics/32864.jpg"
FloatLayout:
Button:
size_hint: 0.20, 0.10
pos_hint: {"x": 0.60, "top": 1}
text: "Search"
on_press: root.add_button()
Button:
size_hint: 0.20, 0.10
pos_hint: {"x": 0.80, "top": 1}
text: "collection"
TextInput:
multiline: False
font_size: 48
size_hint: 0.60, 0.10
pos_hint: {"x": 0, "top": 1}
ScrollView:
size_hint: 0.60, 0.90
StackLayout:
orientation: "lr-tb"
pos_hint: {"x": 0, "top": 0.88}
size_hint: 1, None
height: self.minimum_height
padding: 5
spacing: 5
TestButton:
TestButton:
TestButton:
TestButton:
TestButton:
TestButton:
TestButton:
TestButton:
TestButton:
TestButton:
TestButton:
TestButton:
TestButton:
TestButton:
TestButton:
TestButton:
Edit 4: Getting the error "AttributeError: 'FloatLayout' object has no attribute 'add_button'" when trying to run the add_button() function when the button labeled "search" is pressed