TextInput

49 views
Skip to first unread message

Degenerate Tech

unread,
Aug 15, 2020, 1:06:38 AM8/15/20
to Kivy users support
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
class Ss(BoxLayout):
def __init__(self,col_no=1,**k):
super().__init__(**k)
for __i in range(col_no):
self.__a=TextInput(multiline=0)
self.add_widget(self.__a)

class A(App):
def build(self):
self.b=BoxLayout(orientation="vertical")
for i in range(10):
self.k=Ss(col_no=10)
self.b.add_widget(self.k)

return self.b

A().run()




form above code how can i access different textinput object from A class?

Degenerate Tech

unread,
Aug 15, 2020, 1:10:10 AM8/15/20
to Kivy users support
i want to make a spreadsheet excel like widget to save and view data ..

Elliot Garbus

unread,
Aug 15, 2020, 10:20:50 AM8/15/20
to kivy-...@googlegroups.com

The code below shows how to access each of the textinputs.    I have changed some of you variable names for clarity.

Setting write_tab to false allows you to tab between the text inputs.

 

 

from kivy.app import App
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout


class Row(BoxLayout):                    # defines a row
   
def __init__(self, col_no=1, **k):
       
super().__init__(**k)
       
for i in range(col_no):
            a = TextInput(
multiline=0, write_tab=False# set write_tab False to tab between textinput fields
           
self.add_widget(a)


class A(App):
   
def __init__(self, **kwargs):
       
super().__init__(**kwargs)
       
self.ss = None

    def
build(self):
       
self.ss = BoxLayout(orientation="vertical")
       
for i in range(10):
            row = Row(
col_no=10)
           
self.ss.add_widget(row)
       
return self.ss

   
def on_start(self):
       
print(f'The rows are in reverse order: {self.ss.children}')
       
print(f'Each row has text inputs, also in reverse order: {self.ss.children[0].children}')
        rows =
reversed(self.ss.children)
       
for r,row in enumerate(rows):
            t_inputs =
reversed(row.children)
           
for c, t_input in enumerate(t_inputs):
                t_input.text =
f'C{c}, R{r}'


A().run()

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/3ff60d51-fa34-4e7b-b6fa-f665463a0b5fo%40googlegroups.com.

 

Degenerate Tech

unread,
Aug 15, 2020, 10:44:53 AM8/15/20
to Kivy users support
wow ...nice ,sir can i use enter key to go next text input than tab key?

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
Aug 15, 2020, 11:20:39 AM8/15/20
to kivy-...@googlegroups.com

can i use enter key to go next text input than tab key…

 

That is not provided by the widget, but you could write the code to do that.  If you’re going to create a spreadsheet-like object, you might consider going down the column on enter.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b5e9df4b-9eb7-4180-a1ce-094092532016o%40googlegroups.com.

 

Degenerate Tech

unread,
Aug 15, 2020, 11:43:03 AM8/15/20
to Kivy users support
how to do that ?...can you give a small example please

Elliot Garbus

unread,
Aug 15, 2020, 12:42:23 PM8/15/20
to kivy-...@googlegroups.com

It is quite straight forward.  When you get the on_text_validate event, set the focus on the TextInput in the next column.

Degenerate Tech

unread,
Aug 16, 2020, 12:19:49 AM8/16/20
to Kivy users support
i did ...........

class Row(BoxLayout):                    # defines a row
    def __init__(self, col_no=1, **k):
        super().__init__(**k)
        self.orientation="vertical"

        for i in range(col_no):
            a = TextInput(multiline=0, write_tab=0,on_text_validate=self.on_enter)  # set write_tab False to tab between textinput fields
            self.add_widget(a)
            b=a
    def on_enter(self,instance):
        print(instance)
        a=instance.get_focus_next()
        a.focus=1
        print(a)

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
Aug 16, 2020, 1:27:52 AM8/16/20
to kivy-...@googlegroups.com
👍

Sent from my iPhone

On Aug 15, 2020, at 9:19 PM, Degenerate Tech <sksah...@gmail.com> wrote:


To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/1c82a963-0970-44fb-b22d-c86bbff8bb8bo%40googlegroups.com.

Degenerate Tech

unread,
Aug 16, 2020, 11:31:17 AM8/16/20
to Kivy users support
see on_start() method 

for r,col in enumerate(x):
            print("hello")
            t_inputs = reversed(col.children[0].children)
            print(t_inputs)
            for c, t_input in enumerate(t_inputs):
                t_input.text = f'R{c}, C{r}'


flow of program not entering these two for loop
main.py

Elliot Garbus

unread,
Aug 16, 2020, 12:31:05 PM8/16/20
to kivy-...@googlegroups.com

You consumed the iterator.  One alternative is to convert the iterator into a list.

 


def on_start(self):
    cols =
reversed(self.ss.children)
    x =
list(cols)
   
    
for j in x:
       
print(j.children[0].children)

   
for r,col in enumerate(x):
       
print("hello")
        t_inputs =
reversed(col.children[0].children)
       
print(t_inputs)
       
for c, t_input in enumerate(t_inputs):
            t_input.text =
f'R{c}, C{r}'

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/7b4cc845-e006-4b9e-945c-8bb7cab5e84ao%40googlegroups.com.

 

Degenerate Tech

unread,
Aug 16, 2020, 12:59:05 PM8/16/20
to Kivy users support
Reply all
Reply to author
Forward
0 new messages