我創建了一個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