有人能告诉我我在哪里吗;我的Python登录屏幕出了问题?
我正在为Python电子邮件客户端创建登录屏幕,以下是我迄今为止的代码:有人能告诉我我在哪里吗;我的Python登录屏幕出了问题?,python,tkinter,Python,Tkinter,我正在为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(
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中应该如何做,或者这是一个需要修复的简单错误?提前感谢。有关此小部件的文档如下
我想您应该检索传递给此小部件的值。您可以尝试使用
.get()
方法来实现此目的。这只是一个猜测,因为我没有使用imaplib
或tkinter
的经验,但这似乎是您的问题:
mail.login(user, pword)
如果您检查用户
和pword
的类型,它们将是条目
s
imaplib
但是似乎要求这些参数是带有replace
方法的对象;可能是一根绳子
如果
Entry
s是文本字段,您可能需要从字段中获取文本并传递它,而不是传递整个Entry
对象 您似乎将错误类型的数据传递到imaplib库。它需要一个具有替换方法的对象,而您给它一个条目
,它显然没有该方法。好的,因此将mail.login(user,pword)更改为mail.login(user.get(),pword.get())似乎可以解决问题,谢谢!很乐意帮忙!请随意投票并接受答案!:)