python - Variable function as position -


i trying associate position of button index of list. have 1 list containing many names, , list containing many numeric values. want create function takes position (or other parameter) of button, , associates button position index of list.

for example: when click on first button, function takes first name of list, , takes first numeric value of other list. clicked last button, , function takes last name of list , last numeric value other list.

i did creating many function values, think there more intelligent way this.

.py

n = ["a", "b", "c", "d"] v = [10, 20, 30, 40] x = 0 y = [] = 0 class primeiroscreen(screen):     def __init__(self, **kwargs):         self.name = 'um'         super(screen,self).__init__(**kwargs)      def fc1(self, *args):#i don't know how make variable button position          global x         x = x + v[i]         y.append(n[i])         print (x)         print (y) 

.kv

<primeiroscreen>:     stacklayout:         orientation: 'tb-lr'         gridlayout:             cols: 2             spacing: 10, 10             #padding: 0, 0             size_hint: (1,.8)             button:                 text: "[b]btn1[/b]"                 markup: true                 on_press: root.fc1()             button:                 text: "[b]btn2[/b]"                 font_size: '20dp'                 markup: true                 on_press: root.fc1()             button:                 text: "[b]btn3[/b]"                 font_size: '20dp'                 markup: true                 on_press: root.fc1()             button:                 text: "[b]btn4[/b]"                 font_size: '20dp'                 markup: true                 on_press: root.fc1() 

in case send button position fc1 function

....      gridlayout:         cols: 2         spacing: 10, 10         #padding: 0, 0         size_hint: (1,.8)         button:             text: "[b]btn1[/b]"             markup: true             on_press: root.fc1(1) #woohoo!!!         button:             text: "[b]btn2[/b]"             font_size: '20dp'             markup: true             on_press: root.fc1(2)         button:             text: "[b]btn3[/b]"             font_size: '20dp'             markup: true             on_press: root.fc1(3)         button:             text: "[b]btn4[/b]"             font_size: '20dp'             markup: true             on_press: root.fc1(4)  

and have:

 def fc1(self, i):     global x      x = x + v[i]     y.append(n[i])     print (x)     print (y) 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -