我创建了一个Python的电子邮件客户端的登录界面,这里是我到目前为止的代码:有人能告诉我哪里出错了,这个Python登录屏幕?
import imaplib # import the imap library
from tkinter import * #import everything from the tkinter library (for use with gui)
global user
global pword
global root
def LoginClick():
mail = imaplib.IMAP4_SSL('elwood.yorkdc.net')
mail.login(user, pword)
LoginClick.mainloop()
root = Tk() #creates new window
root.title('Login') #sets title of window
root.configure(background='black') #change background colour of window
instruction = Label(root, text='Please Login\n') #Creates label
instruction.configure(background='black', fg='white') #Configuring label style
instruction.grid(sticky=E) #Sticks to eastern edge
userL = Label(root, text='Username: ')
userL.configure(background='black', fg='white')
pwordL = Label(root, text='Password: ')
pwordL.configure(background='black',fg='white')
userL.grid(row=1, sticky=W)
pwordL.grid(row=2, sticky=W)
user = Entry(root)
pword = Entry(root, show='*')
user.grid(row=1, column=1)
pword.grid(row=2, column=1)
loginB = Button(root, text='Login', command=LoginClick)
loginB.grid(columnspan=2, rowspan=2, sticky=W)
root.mainloop()
当我运行的模块并输入我的凭据到GUI我得到以下错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Marcus\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:\Users\Marcus\Desktop\Networking\IMAP.py", line 11, in LoginClick
mail.login(user, pword)
File "C:\Users\Marcus\AppData\Local\Programs\Python\Python36-32\lib\imaplib.py", line 588, in login
typ, dat = self._simple_command('LOGIN', user, self._quote(password))
File "C:\Users\Marcus\AppData\Local\Programs\Python\Python36-32\lib\imaplib.py", line 1180, in _quote
arg = arg.replace('\\', '\\\\')
AttributeError: 'Entry' object has no attribute 'replace'
我是否完全错误的轨道与如何在Python中完成或这是一个简单的错误来解决?提前致谢。
您似乎将错误类型的数据传递给imaplib库。它期望一个带有'replace'方法的对象,并且你给它一个'Entry',这显然没有这个方法。 – Carcigenicate