2017-04-19 23 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對象。

相關問題