Keypad making help

10 views
Skip to first unread message

Chris Chenoweth

unread,
Sep 29, 2018, 1:11:06 AM9/29/18
to Kivy users support
I'm trying to make a keypad and whenever a button is pressed it'll send a corresponding number to a verification function. But whenever I add a number it sends me errors saying it can't do it. Please help.
from kivy.config import Config
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout

Config.set('graphics', 'width', 300)
Config.set('graphics', 'height', 300)
Config.set('graphics', 'resizable', 'False')
Config.set('graphics', 'borderless', 'True')


class Keypad(App):

def build(self):
layout = GridLayout(cols=3)
btn1 = Button(text='1',)
btn2 = Button(text='2', on_press=verification(2))
btn3 = Button(text='3', on_press=verification)
btn4 = Button(text='4', on_press=verification)
btn5 = Button(text='5', on_press=verification)
btn6 = Button(text='6', on_press=verification)
btn7 = Button(text='7', on_press=verification)
btn8 = Button(text='8', on_press=verification)
btn9 = Button(text='9', on_press=verification)
btn1.bind(on_press=verification(1))
layout.add_widget(btn1)
layout.add_widget(btn2)
layout.add_widget(btn3)
layout.add_widget(btn4)
layout.add_widget(btn5)
layout.add_widget(btn6)
layout.add_widget(btn7)
layout.add_widget(btn8)
layout.add_widget(btn9)
return layout


def verification(instance):
print(instance)
"""attempts = 4
password = []
actual_password = [1, 2, 3, 4]
while attempts >= 0:
attempts = attempts - 1
password.append(x)
print(password)
if password == actual_password:
print("Your in")"""


Keypad().run()

ZenCODE

unread,
Sep 29, 2018, 11:02:30 AM9/29/18
to Kivy users support
Some of the bindings are calling the function instead of just passing the function in. Probably just an oversight as you are doing it correctly elsewhere....

btn2 = Button(text='2', on_press=verification(2))

should be

btn2 = Button(text='2', on_press=verification)

and

btn1.bind(on_press=verification(1))

should be

btn1.bind(on_press=verification)



Reply all
Reply to author
Forward
0 new messages