Я относительно новичок в Киви.Я пытаюсь прочитать номер телефона, который вводится в текстовый ввод с помощью кнопки «Экстренные контакты» моего приложения.С этим номером я хотел бы отправить сообщение, используя twilio.Сообщение можно отправить, нажав кнопку «Позвонить семье» внутри кнопки «Просмотр сердечного ритма».Однако я не слишком уверен, как вернуть ввод текста, и небольшое руководство действительно поможет.
from kivy.lang import Builder
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.clock import Clock
from kivy.uix.popup import Popup
from kivy.uix.textinput import TextInput
import random
from twilio.rest import Client
#twilio account info
#ACCOUNT SID AND TOKEN HERE. SORRY I CANT REALLY PROVIDE THEM
account_sid = '--------------'
auth_token = '------------'
client = Client(account_sid, auth_token)
Builder.load_string("""
<Bump@Button>:
font_size: 40
color: 1,1,1,1
size_hint: 0.8,0.4
background_color: 1,0,0,1
<Back@Button>:
text: 'back'
pos_hint: {'x':0,'y':0.9}
size_hint: 0.2,0.1
<BoxLayout>:
font_size: 40
color: 1,0,1,1
background_color: 0,0,1,1
<menu>:
Bump:
text: "View Heart Rate"
pos_hint: {"center_x": .5, 'center_y':.3}
on_press: root.manager.current ='heartrate'
on_press: root.manager.transition.direction = 'left'
Bump:
text: "Emergency Contacts"
pos_hint: {'center_x': 0.5, 'center_y':0.7}
on_press: root.manager.current = 'contact'
on_press: root.manager.transition.direction = 'left'
Label:
text: "Remity Biotechnologies"
pos_hint: {'center_x': 0.5, 'center_y':0.95}
<heartrate>:
color: 1,1,1,1
Bump:
id: fam
text: "Call Family"
pos_hint: {'center_x':0.5,'center_y':0.7}
on_press: root.schedule_event()
Label:
id: temp_label
font_size: 24
text: ''
pos_hint:{'center_x':0.5,'center_y':0.3}
Back:
on_press: root.manager.current = 'menu'
on_press: root.manager.transition.direction = 'right'
<contact>:
orientation: "vertical"
Label:
text: "Enter Emergency Contact"
pos_hint:{'center_x':0.2,'center_y':0.75}
BoxLayout:
height: "80dp"
size_hint_y: 0.1
TextInput:
size_hint_x: 20
Button:
text: "Save"
size_hint_x: 25
Back:
on_press: root.manager.current = 'menu'
on_press: root.manager.transition.direction = 'right'
<confirm@Popup>:
id: pop
size_hint: 0.2,0.2
title: 'Message Sent'
auto_dismiss: True
""")
class confirm(Popup):
pass
class menu(Screen):
def update(self,dt):
pass
class heartrate(Screen):
r = 0
def __init__(self, **kwargs): #initializes it to change im guessing
super(heartrate, self).__init__(**kwargs)
self.change = self.ids.temp_label
def update(self,dt): #update random number
self.r = str(random.randint(1,101))
print(self.r)
t = str(self.r)
self.change.text = t
def schedule_event(self, **kwargs):
#event that sends message and confirms message was sent
if 'fam' in self.ids:
message = client.messages \
.create(
body="This is an automated message to let you know your son is showing signs of atrial fibrillation!",
from_='---------', #TWILIO PHONE NUMBER
to='---------' #NUMBER THAT THE USER ENTERS
)
print(message.sid)
c = confirm()
c.open()
class contact(Screen):
def update(self,dt):
pass
class ScreenManager(ScreenManager):
def update(self,dt):
self.current_screen.update(dt)
#screens screens screens
sm = ScreenManager()
sm.add_widget(menu(name='menu'))
sm.add_widget(heartrate(name='heartrate'))
sm.add_widget(contact(name='contact'))
class SimpleKivy4(App):
def build(self):
Clock.schedule_interval(sm.update,1)
return sm
if __name__ == "__main__":
SimpleKivy4().run()