用功能绑定Kivy文本输入

时间:2015-05-25 10:39:20

标签: android python kivy

我写了一个kivy脚本,其中我无法使用我的回调函数绑定文本输入。

在这里,我编写了一个脚本,其中应用程序将电子邮件地址作为文本输入,然后在按下按钮时,它将向电子邮件地址发送电子邮件。

from kivy.app import App
from kivy.uix.button import Button
import webbrowser
from functools import partial
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.popup import Popup
import re
import urllib2
import time
import os
import sys
import smtplib
import string
import time
from functools import partial

# Here I have predefine some values already which will be used in script
fromaddr = 'email id will be wriiten in script already'
msg = "hello world"
uname = 'email id will be written in script already'
pword = 'password will be wriiten in script already'

#this is just popup for email sent 
def once_pop(instance):
    popup = Popup(title='NOTE',
                content=Label(text='Email sent',halign='center'),
                size_hint=(None, None), size=(400, 400),auto_dismiss=True)
    popup.open()

#this is my callback function in which email will be sent
#email id will be taken from text input and in callback function email will be sent to that email id

def callback(instance,self):
    server = smtplib.SMTP('smtp.gmail.com:587')
    server.ehlo()
    server.starttls()
    server.login(uname,pword)
    self.t.text=destinationemailid
    server.sendmail(fromaddr, destinationemailid, msg1)

class TestApp(App):
    try:
        urllib2.urlopen('http://www.google.com')    

        def build(self):
            bx=FloatLayout(size=(300, 300))
            l=Label(text='\nUSE THIS APPLICATION ON YOUR OWN RISK.\nTHIS APP IS MADE BY WARL0CK.\nWE WILL NOT RESPONSIBLE FOR ANY KIND OF DAMAGE.',font_size=21,size=(470,100),size_hint=(None,None),pos=(0,650), halign='center')
            t=TextInput(font_size=20,size=(470,39),size_hint=(None,None),text='Enter Email Id to you want to send email',pos=(0,580),multiline=False)
            b=Button(text="SEND EMAIL",font_size=18,background_color=[1,1,3,1],size=(250,75),size_hint=(None,None),pos=(0,470))
            b.bind(on_press=once_pop)   
            b.bind(on_release=final)        
            c=Button(text= 'EXIT',font_size=18,background_color=[1,1,1,1],size=(100,75),pos=(330,470),size_hint=(None,None))
            c.bind(on_release=exit)

            bx.add_widget(l)
            bx.add_widget(t)
            bx.add_widget(b)
            bx.add_widget(c)
            return bx
    except:
        box = BoxLayout(orientation='vertical')
        textlabel=Label(text='  INTERNET IS REQUIRED FOR THIS APP.\nPLEASE START INTERNET & RESTART APP.',size_hint=(None,None),size=(410,140), halign='center')
        textbutton=Button(text='Exit',size=(410,80),size_hint=(None,None))
        textbutton.bind(on_release=exit)
        box.add_widget(textlabel)
        box.add_widget(textbutton)
        popup = Popup(title='ERROR !', content=box, size_hint=(None, None), size=(450, 300),auto_dismiss=False)

        popup.open()

if __name__ == '__main__':
    TestApp().run()

0 个答案:

没有答案