Python Forum
[Kivy] Add buttons to StackLayout after 'Enter'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Kivy] Add buttons to StackLayout after 'Enter'
#1
Hi! I'm beginner in Python.
I want to add buttons to Wyniki(StackLayout) when I write something in TextInput and click Enter. I have written a program that doesn't work :(
I guess that the issue is in line 39 (with 'self'), but I dont know how to solve this problem..
Anyone can help me?


import kivy
from kivy.app import App
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.metrics import dp
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.stacklayout import StackLayout


kivy.require('2.1.0')


class Szukajka(BoxLayout):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.orientation = 'horizontal'
        self.padding = dp(10)
        self.size_hint = (1,None)
        self.size = (self.width,dp(60))
        self.szukaj = TextInput(multiline=False, padding=(8,10,8,10), on_text_validate=Wyniki.tworz)
        self.add_widget(self.szukaj)
        self.lupa = Button(text='Szukaj', size_hint=(None,1), size=(dp(100),self.height))
        self.add_widget(self.lupa)

class Wyniki(StackLayout):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
    def tworz(self):
        for i in range(0, 5):
            self.przycisk = Button(text=str(i), background_color=(0.7, 0.5, 0, 0.8), size_hint=(1, None),
                              size=(dp(300), dp(100)))
            self.add_widget(self.przycisk)

class MainApp(App):
    pass

if __name__ == "__main__":
    MainApp().run()
Yoriz write Nov-21-2022, 02:07 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Attached Files

Thumbnail(s)
   
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020