+1 vote
by
Gentlemen... I've only been programming for 5 months recently and decided to try kivy... Please don't swear on my code... I looked a lot of vidos on youtube and a lot of sites about kivy... But still kivy is hard for me....
First of all I don't understand how to make the code be executed not all at once, but gradually.... Like I have a problem I want to make as many buttons as user set in TextInput and then give this value to the next cycle, but the code is executed all at once I don't understand what to do Help, please... This is what I wanted to do

class ScreenTwo7(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.name = 'Sc7'
AncL1 = AnchorLayout(anchor_y = 'top')
NumberS1 = GridLayout(cols = 2, spacing = 2, padding = [0, 100, 0, 100] )
AncL1.add_widget(NumberS1)
for i in range(1):

self.t2 = TextInput(text = 'Введите кол-во элементов выборки...')
NumberS1.add_widget(self.t2)

self.b2 = Button(text = 'Вывести поля для выборки')
self.b2.bind(on_press = self.cicle)
NumberS1.add_widget(self.b2)


self.add_widget(AncL1)
def cicle(self, t):
for n in range(int(t.text)):
NumberS1 = GridLayout(cols = 2, spacing = 2, padding = [0, 100, 0, 100] )
self.t2 = TextInput(text = '#1')
NumberS1.add_widget(self.t2)
self.add_widget(NumberS1)
And there was also a question about how to transfer a value from one class to another... I wanted the user to press the 7 button on one screen, this digit would be remembered in some variable and transferred to the next screen thanks for the answers... If there are any...
by
Format the code properly
by
by
Alan Gibizov , Dear Alan, I have not seen any rules for framing questions on the hubr forum, if such a rule exists I would be happy to read it. This was the first, and the second, in my opinion, you should not write empty words, "clogging" thus the information space. If you can't tell me anything, then... I didn't mean to insult anyone
by
Kirill312 , bad. You didn't read the rules when you registered, but you clicked "I agree". You were told that the code should be properly placed and formatted, you do not bother to understand. I clearly pointed out to you that this is the problem, but you still expect to do everything for you. Poke your nose in the rules, abate the code for you, and because the code is in the screenshot - even re-post it for you. Do you really think so?
by
All because you don't read the documentation. Just now you haven't read the documentation for the forum you're on, and you don't know how to form questions and code here.
With that kind of spiteful attitude toward business and the people on whom you depend, you can immediately retrain as a superintendent.
by
Kirill312 where?
by
efters , done
by
Can the code in a normal form, not a picture, where you can not read anything?
by
Alan Gibizov Yes, you're right. Sorry, I'll fix it soon... But I'm not asking to fix something for me - I seriously lack documentation (the ones in English, or kv files I do not want to go there) You can not tell me anything?

1 Answer

+1 vote
by
To make sure that the code is not executed all at once, but depending on the user's actions, you need to use events.
For example, on_text_validate of the TextInput widget.
#!/usr/bin/python
import kivy
from kivy.app import App
from kivy.uix.textinput import TextInput
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button

class RootWidget(GridLayout):
def __init__(self, **kwargs):
super(RootWidget, self).__init__(**kwargs)
self.cols = 2
self.add_widget(CreateInput(multiline=False))

class CreateInput(TextInput):
def on_text_validate(self):
for i in range(int(self.text)):
self.parent.add_widget(Button(text=str(i)))

class MyApp(App):
def build(self):
return RootWidget()

if __name__ == "__main__":
MyApp().run()
by
Thank you very much! A healthy person's answer) And how to transfer for example a variable from one class to another? I.e. from one screen to another?
by
Kirill312 ,
In many different ways. For example, as in the example above, by using self.parent (self.children, backwards) if they are closely related widgets. If you're using kv files, you can do this in them by assigning identifiers to widgets. Also, in kv your App class is globally accessible through the app variable. You can use this.
...