是否可以将tkinter Entry字段编码为utf-8?

问题描述 投票:0回答:1

我是第一次和tkinter玩弄,有一个问题。有没有一种方法可以编码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'

是否存在编码输入字段的正确方法?谢谢!

python tkinter tkinter-entry
1个回答
0
投票

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

username = my_username.get().encode('utf-8')
© www.soinside.com 2019 - 2024. All rights reserved.