function - Python [Tkinter] Application not displaying all information -
i working on python tkinter application allows user send email user using gui window. running on python 3.4.2, , have created [log in] window , [compose message] window. within program have created many entries user enters data, 1 email, password, message, subject, to, , etc. have function print() out data user has entered. problem 3/6 entry results showing in console. can please @ code , tell me wrong. friends please not flag question, i'm trying learn why isn't working can work on , publish online, if want can credit in work if that's want ;) below have provided screen shot of output in console, , 2 different windows i've created.
the code:
#-->project name : email buddy #-->project start date : monday, august 24th, 2015. #-->project written : pamal mangat. #-->project end date : #imports pil import image, imagetk import webbrowser import email import sys import smtplib import tkinter def sendmail(recipient, sender, subject, message, password): #function sends email. msg = email.message_from_string(message) msg['from'] = sender msg['to'] = recipient msg['subject'] = subject connect = smtplib.smtp("smtp.live.com",587) connect.ehlo() connect.starttls() connect.ehlo() connect.login(password, password) connect.sendmail(sender, recipient, msg.as_string()) connect.quit() def root(): def testinfo(email, password, sender, reciever, message, subject): #function checks if info entered. print("email : " + email) print("password : " + password) print("from : " + sender) print("to : " + reciever) print("message : " + message) print("subject : " + subject) #created send message (compose message) window (root = compose message) >>> user redirected page after signing in. root = tkinter.tk() root.title("email buddy | compose message") #root text root_text1 = tkinter.label(root, text="to", font="bizon 20 bold", fg="red") root_text1.place(x=20, y=50) root_text2 = tkinter.label(root, text="subject", font="bizon 20 bold", fg="red") root_text2.place(x=20, y=145) root_text3 = tkinter.label(root, text="message", font="bizon 20 bold", fg="red") root_text3.place(x=20, y=235) #root entries to_variable = tkinter.stringvar() to_entry = tkinter.entry(root, bd=4, width=28, textvariable=to_variable, font="helvetica 16 italic") to_entry.focus() to_entry.place(x=20, y=95) subject_variable = tkinter.stringvar() subject_entry = tkinter.entry(root, bd=4, width=28, textvariable=subject_variable, font="helvetica 16 italic") subject_entry.focus() subject_entry.place(x=20, y=190) message_variable = tkinter.stringvar() message_entry = tkinter.entry(root, textvariable=message_variable, bd=4, width=28, font="helvetica 16 italic") message_entry.focus() message_entry.place(x=20, y=280) email = email_variable.get() password = password_variable.get() sender = email_variable.get() reciever = to_variable.get() message = message_variable.get() subject = subject_variable.get() send_button = tkinter.button(root, text="send", fg="white", bg="green", width=8, height=2, font="bizon 8 bold", command=lambda:testinfo(email, password, sender, reciever, message, subject)) send_button.place(x=300, y=355) #locks window size. root.minsize(385,425) root.maxsize(385,425) #changes favicon in upper-left corner of master window. root.iconbitmap(r"c:\users\pamal\desktop\documents\python folder\python projects\email buddy\images\emailbuddy_icon.ico") root.mainloop() #created main log in window (master = log in). master = tkinter.tk() master.title("email buddy | log in") #master text master_text = tkinter.label(master, text="sign in", font="bizon 36 bold", fg="red") master_text.place(x=90, y=20) master_text2 = tkinter.label(master, text="email", font="bizon 20 bold") master_text2.place(x=20, y=100) master_text3 = tkinter.label(master, text="password", font="bizon 20 bold") master_text3.place(x=20, y=190) #master entries email_variable = tkinter.stringvar() email_entry = tkinter.entry(master, bd=4, width=25, textvariable=email_variable, font="helvetica 16 italic", fg="red") email_entry.focus() email_entry.place(x=20, y=140) password_variable = tkinter.stringvar() password_entry = tkinter.entry(master, bd=4, width=25, textvariable=password_variable, font="helvetica 16 italic", fg="red") password_entry.focus() password_entry.place(x=20, y=230) #sign-in button signin_button = tkinter.button(master, text="sign in", font="bizon 8 bold", fg="white", bg="green", width=8, height=2, command=lambda:root()) signin_button.place(x=265, y=295) #locks window size master.minsize(350, 350) master.maxsize(350, 350) #changes favicon in upper-left corner of master window. master.iconbitmap(r"c:\users\pamal\desktop\documents\python folder\python projects\email buddy\images\emailbuddy_icon.ico") master.mainloop()
screenshot:
first window
second window
the crux of problem getting values of variables when first create button, @ point to, subject , message blank.
the proper way code gui values when need them, , not before. eliminates need lambda
; lambda necessary , makes code harder write, harder understand, , harder modify.
also, advice not use stringvars, , modify testinfo
fetch data @ time needs it. use of stringvar
1 more object need keep track of, , unnecessary unless you're making use of special features of objects (which you're not).
def testinfo(): reciever = to_entry.get() email = email_entry.get() password = password_entry.get() sender = email_entry.get() message = message_entry.get() subject = subject_entry.get() print("email : " + email) print("password : " + password) print("from : " + sender) print("to : " + reciever) print("message : " + message) print("subject : " + subject) ... send_button = tkinter.button(..., command=testinfo)
Comments
Post a Comment