关于文本输入框,无法在Tkinter上使用.get()函数

时间:2019-01-01 02:56:16

标签: python tkinter

我正在尝试创建自己的“电子邮件界面”,在该界面中,我需要通过输入框收集来自用户的输入,以在电子邮件发送过程中使用它们。问题在于.get()功能似乎总是出错。

line 32, in send_it email_resipient = Three.get()
AttributeError: 'NoneType' object has no attribute 'get'

请帮助,我已经研究了几个小时,但似乎找不到解决方法。这是代码。...

from tkinter import *
import smtplib


root = Tk()
root.title("Jon's Email Service")
root.geometry("800x640+0+0")

Label(root, text="Jon's Email Service", font=("arial", 60, 
"bold"), fg="black").pack()

Label(root, text="User's Email address {Has to be gmail} ", 
font=("arial", 20,), fg="black").pack()

One = Entry(root,width=40, bg="white").pack()


Label(root, text="User's Gmail Password", font=("arial", 20,), 
fg="black").pack()

Two = Entry(root, width=40, bg="white").pack()



Label(root, text="Email Recipient", font=("arial", 20,), 
fg="black").pack()

Three = Entry(root,width=40, bg="white").pack()
Label(root, text="The Message", font=("arial", 20,), 
fg="black").pack()

Four = Entry(root, width=60, bg="white").pack()

def send_it():
    email_resipient = Three.get()
    emailUser = One.get()
    user_Password = Two.get
    msg = Four.get()
    print(emailUser)
    server = smtplib.SMTP("smtp.gmail.com", 587)
    server.starttls()
    server.login(emailUser, user_Password)
    server.sendmail(emailUser, email_resipient, msg)
    server.quit()
Label(root, text="Email Is Sent!", font=("arial", 20,), 
fg="black").pack()

send = Button(root, text="Send", width = 40, bg = "lightblue", 
command = send_it).pack()

root.mainloop()

1 个答案:

答案 0 :(得分:0)

您不应该在赋值字符串的末尾使用$file_name = $_FILES['userfile']['name'][$i]; $gambar[$i] = ''; //set it to blank by default for your checks further down if($file_name != ''){ $explode = explode('.',$file_name); // die(print_r($explode)); $ekstensi = pathinfo($file_name, PATHINFO_EXTENSION); $bulan = date('M'); $tahun = date('y') ; $kode = $this->session->userdata('kode_puskesmas'); $new_file_name = $explode[1].'_'.$kode.'_'.$bulan.$tahun.'.'.$ekstensi; $tmp_name = $_FILES['userfile']['tmp_name'][$i]; move_uploaded_file($tmp_name, "file/".$new_file_name); $gambar[$i] = $new_file_name; } ,应该首先赋值变量,然后.pack()赋值:

.pack()

该变量获取from tkinter import * import smtplib root = Tk() root.title("Jon's Email Service") root.geometry("800x640+0+0") Label(root, text="Jon's Email Service", font=("arial", 60, "bold"), fg="black").pack() Label(root, text="User's Email address {Has to be gmail} ", font=("arial", 20,), fg="black").pack() One = Entry(root,width=40, bg="white") One.pack() #here Label(root, text="User's Gmail Password", font=("arial", 20,), fg="black").pack() Two = Entry(root, width=40, bg="white") Two.pack() # here Label(root, text="Email Recipient", font=("arial", 20,), fg="black").pack() Three = Entry(root,width=40, bg="white") Three.pack() # here Label(root, text="The Message", font=("arial", 20,), fg="black").pack() Four = Entry(root, width=60, bg="white") Four.pack() # here def send_it(): email_resipient = Three.get() emailUser = One.get() user_Password = Two.get msg = Four.get() print(emailUser) server = smtplib.SMTP("smtp.gmail.com", 587) server.starttls() server.login(emailUser, user_Password) server.sendmail(emailUser, email_resipient, msg) server.quit() Label(root, text="Email Is Sent!", font=("arial", 20,), fg="black").pack() send = Button(root, text="Send", width = 40, bg = "lightblue", command = send_it).pack() root.mainloop() 函数的返回值,实际上不是pack()或其他任何值,而Entry的返回值为pack()