2017-04-19 31 views
-1

我创建了一个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中完成或这是一个简单的错误来解决?提前致谢。

+0

您似乎将错误类型的数据传递给imaplib库。它期望一个带有'replace'方法的对象,并且你给它一个'Entry',这显然没有这个方法。 – Carcigenicate

回答

1

这个插件的文档here

我想你想你检索传递给此插件的值。你可以尝试使用.get()方法。

+0

好吧,如此改变mail.login(用户,pword)mail.login(user.get(),pword.get())似乎解决了这个问题,谢谢! – Imminence

+0

乐意帮忙!随时upvote并接受答案! :) – Astrom

0

这只是一种猜测,因为我有imaplibtkinter没有经验,但是这似乎是你的问题:

mail.login(user, pword) 

如果检查的userpword类型,他们将Entry秒。

imaplib但是似乎要求这些参数是具有replace方法的对象;可能是一串。

如果Entry s是文本字段,那么您可能需要从字段中抓取文本并传递该文本,而不是传递整个对象的Entry对象。

相关问题