Kivy and Python GUI
I can create a label programmatically, but am unable to remove the same label
If the label is already part of the GUI, I can remove it, but not a label I have created after app is running.
The error is:
Thanks
pythoncode:
kv code:
I can create a label programmatically, but am unable to remove the same label
If the label is already part of the GUI, I can remove it, but not a label I have created after app is running.
The error is:
Can you help please ?File "C:\Users\evan\Desktop\Raspberry\v10.py", line 21, in removeMyLabel
self.remove_widget(self.ids.new_lb)
^^^^^^^^^^^^^^^
Thanks
pythoncode:
Python:
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.uix.button import Button
from kivy.uix.label import Label
# manually setting in script
Window.size = (800, 480)
class YourWidget(Widget):
def __init__(self, **kwargs):
super(YourWidget, self).__init__(**kwargs)
pass
def addMyLabel(self):
new_lb = Label(text="X", size_hint=(None, None), size=(50, 50), pos=(50, 50))
self.add_widget(new_lb)
def removeMyLabel(self):
self.remove_widget(self.ids.new_lb)
class V10App(App):
def build(self):
Window.clearcolor = (0.2, 0.2, 0.2, 1)
return YourWidget()
if __name__ == "__main__":
V10App().run()
kv code:
Code:
<YourWidget>:
Button:
id: button1
text: 'Add The Label'
pos: (100, 320)
size: (450, 50)
size_hint: (None, None)
on_release: root.addMyLabel()
Button:
id: button2
text: 'Remove The Label'
pos: (100, 220)
size: (450, 50)
size_hint: (None, None)
on_release: root.removeMyLabel()