我正在为 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 中完成,还是这是一个需要修复的简单错误?提前致谢。
关于这个小部件的文档在这里
我猜您想检索传递给此小部件的值。您可以尝试使用.get()
这样做的方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句