I've been trying to fine a solution for a while. I rather not create the button in python, as I'm trying to keep the style away from the functionality. It reports this error every time I try to use Object Property. I've scoured all over trying a bunch of solutions on stackoverflow, so I'm hoping someone can help me out.
TypeError: bind() takes exactly 2 positional arguments (0 given)
As for the actual code, here is the python:
# Function import libraries
import sys
import json
import googlemaps
import pygatt
import time
import asyncio
from bleak import discover
from urllib.request import urlopen
from twilio.rest import Client
import asynckivy as ak
from asynckivy.process_and_thread import \
thread as ak_thread, process as ak_processt
# UI import libraries
from kivy.app import App
from kivy.properties import ObjectProperty
from kivy.properties import StringProperty
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.label import Label
from kivy.uix.image import Image
from functools import partial
from kivy.event import EventDispatcher
class Screen1(Screen):
def __init__ (self,**kwargs):
super (Screen1, self).__init__(**kwargs)
pairbtn = ObjectProperty(None)
pairbtn.bind(on_press=self.pair_pressed)
# self.add_widget(pairbtn)
def pair_pressed(self, event):
async def run():
devices = await discover()
for d in devices:
print(d)
if (str(d).find('DSD TECH') != -1):
address = str(d)[0:17]
print("Device Discovered" + address)
exit()
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
class Screen2(Screen):
pass
class esosApp(App):
def build(self):
screen_manager = ScreenManager()
screenone = Screen1(name='s1')
screentwo = Screen2(name='s2')
screen_manager.add_widget(screenone)
screen_manager.add_widget(screentwo)
return screen_manager
if __name__ == '__main__':
esosApp().run()
And here is the kv file (screen2 omitted):
#:kivy 1.11.1
<Screen1>:
orientation: "vertical"
pairbtn: pairbtn
canvas.before:
Color:
rgb: 0.965,0.965, 0.965
Rectangle:
pos: self.pos
size: self.size
Image:
source: 'icon.png'
size: self.texture_size
AnchorLayout:
anchor_y: 'top'
BoxLayout:
size_hint: 1,.07
canvas.before:
Color:
rgb: 0.6745 , 0.8353 , 0.8784
Rectangle:
pos: self.pos
size: self.size
Image:
source: 'Logo.PNG'
size: self.texture_size
AnchorLayout:
anchor_x: 'center'
anchor_y: 'bottom'
padding: (0, 10, 0, 10)
Button:
id: pairbtn
text: "Pair Device"
background_normal: ''
background_color: 0.6745 , 0.8353 , 0.8784, 1
size_hint: (.8, .1)