+1 vote
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):
self.name = 'Sc7'
AncL1 = AnchorLayout(anchor_y = 'top')
NumberS1 = GridLayout(cols = 2, spacing = 2, padding = [0, 100, 0, 100] )
for i in range(1):

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

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

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')
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...
Format the code properly
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
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?
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.
Kirill312 where?
efters , done
Can the code in a normal form, not a picture, where you can not read anything?
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
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.
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

class CreateInput(TextInput):
def on_text_validate(self):
for i in range(int(self.text)):

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

if __name__ == "__main__":
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?
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.