谁能告诉我,我在这个Python登入界面上做错了什么?

2024-04-26 20:34:19 发布

您现在位置: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中应该如何实现这一点上是完全错误的,还是这是一个需要修复的简单错误?提前谢谢。你知道吗


Tags: textinimportconfigurerootgridfilerow
2条回答

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

mail.login(user, pword)

如果您检查userpword的类型,它们将是Entrys

imaplib但是似乎要求这些参数是带有replace方法的对象;可能是字符串。你知道吗

如果Entry是文本字段,则可能需要从字段中获取文本并传递它,而不是传递整个Entry对象。你知道吗

关于这个小部件的文档是here

我猜你想检索你传递给这个小部件的值。您可以尝试使用.get()方法来实现这一点。你知道吗

相关问题 更多 >