有没有一种方法可以将tkinter Entry字段编码为utf-8?

时间:2020-04-25 20:59:40

标签: python tkinter tkinter-entry

我是第一次和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'

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

1 个答案:

答案 0 :(得分:1)

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

username = my_username.get().encode('utf-8')
相关问题