Kivy needs to access the 'v_pb' and 'max_email' variables from the 'def sendMail (listing):' function. While only mastering python
def sendMail(listing): v_pb = 0 HOST = listing[0] SUBJECT = listing[1] FROM = listing[2] userName = listing[3] passWord = listing[4] fileText = listing[5] s_email = listing[6].split() server = smtplib.SMTP_SSL(HOST, 465) server.login(userName, passWord) max_email = len(s_email) for i in s_email: msg = MIMEMultipart() msg['From'] = FROM msg['Subject'] = SUBJECT msg['To'] = str(i) msg.attach(MIMEText(fileText, 'plain')) server.send_message(msg) v_pb +=1 server.quit() class SendlerApp(App): def build(self): gl = GridLayout() host_txt = TextInput(multiline=False) sub_txt = TextInput(multiline=False) from_txt = TextInput(multiline=False) user_txt = TextInput(multiline=False) pass_txt = TextInput(multiline=False) msg_txt = TextInput(font_size=24) mail_txt = TextInput(font_size=24) btn_start = Button(text="Start",on_press=lambda *a: sendMail( listing=(host_txt.text, sub_txt.text, from_txt.text, user_txt.text, pass_txt.text, msg_txt.text, mail_txt.text))) progress_bar = ProgressBar(max=max_email, size_hint=(1, .1)) # получить доступ к этой переменной из def sendMail(listing): progress_bar.value = v_pb # получить доступ к этой переменной из def sendMail(listing): gl.add_widget(host_txt) gl.add_widget(sub_txt) gl.add_widget(from_txt) gl.add_widget(user_txt) gl.add_widget(pass_txt) gl.add_widget(msg_txt) gl.add_widget(mail_txt) bl2.add_widget(btn_start) gl.add_widget(progress_bar) return gl if __name__ == '__main__': SendlerApp().run()
sendMailfunctionsendMailquite possible to make an application's class method, and thev_pbandmax_emailsimply class fields. By the way, then the parameters of the function can also not be transferred each time, but to make them fields of the class, and from the function (method) simply refer to them directly. - insolor