【发布时间】:2015-08-31 00:40:30
【问题描述】:
我目前正在开发一个 python tkinter 应用程序,该应用程序允许用户使用 GUI 窗口向用户发送电子邮件。我在 python 3.4.2 上运行,并创建了一个 [登录] 窗口和一个 [撰写消息] 窗口。在我的程序中,我创建了许多用户输入数据的条目,一个用于电子邮件、密码、消息、主题、收件人等。然后我有一个函数 print() 输出用户输入的所有数据。唯一的问题是控制台中只显示了 3/6 的条目结果。有人可以看看我的代码并告诉我出了什么问题。我的朋友请不要标记我的问题,我只是想了解为什么这不起作用,以便我可以处理此问题并在线发布,如果您愿意,如果您愿意,我可以在我的工作中归功于您;)下面我提供了控制台中输出的屏幕截图,以及我创建的 2 个不同的窗口。
守则:
#-->Project name : Email Buddy
#-->Project start date : Monday, August 24th, 2015.
#-->Project written by : Pamal Mangat.
#-->Project end date :
#Imports
from PIL import Image, ImageTk
import webbrowser
import email
import sys
import smtplib
import tkinter
def sendMail(recipient, sender, subject, message, password):
#Function sends the 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 all info is entered.
print("Email : " + email)
print("Password : " + password)
print("From : " + sender)
print("To : " + reciever)
print("Message : " + message)
print("Subject : " + subject)
#Created a send message (compose message) window (root = Compose Message) >>> User is redirected to this 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 a 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()
截图:
第一个窗口
第二个窗口
【问题讨论】:
标签: python function user-interface tkinter