有没有办法将tkinter输入字段编码为utf8?

2024-05-15 09:23:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我第一次和特金特鬼混,有个问题。有没有办法对tkinter输入字段进行编码?这是我的密码:

my_username = Entry(window,width=10)
my_username.grid(column=1, row=0)

#a few lines that have nothing to do with username

username = my_username.encode('utf-8')

问题是:

Traceback (most recent call last):
  File "project.py", line 34, in <module>
    username = my_username.encode('utf-8')
AttributeError: 'Entry' object has no attribute 'encode'

有没有合适的方法对输入字段进行编码? 谢谢


Tags: 密码编码tkintermyusernamecolumnwindowwidth
1条回答
网友
1楼 · 发布于 2024-05-15 09:23:50

不,您不能对小部件本身进行编码,因为编码是一个字符串操作,而小部件不是字符串。但是,您可以对从小部件获得的数据进行编码

username = my_username.get().encode('utf-8')

相关问题 更多 >