简体   繁体   English

有没有办法在 tkinter python 的标签小部件中打印十六进制和字节?

[英]Is there any way to print hexadecimal and bytes in label widget in tkinter python?

I have been working on a class project to write an encryption code in python.我一直在做一个类项目,用python编写加密代码。 I have used AES encryption.我使用了 AES 加密。 But now while creating a graphical interface using Tkinter, I can't print ciphered text as it is in hexadecimal.但是现在在使用 Tkinter 创建图形界面时,我无法打印十六进制的密文。 If anyone knows how to print hexadecimal or bytes in the label widget in Tkinter then please let me know.如果有人知道如何在 Tkinter 的标签小部件中打印十六进制或字节,请告诉我。 Thanks.谢谢。

ciphertext = ciphertext + list(encrypt(plaintext.encode(), key, AES.MODE_ECB))
cipher_label = Label(win, text='Cipher: ' + binascii.hexlify(bytes(ciphertext)))
cipher_label.place(x=80, y=270)

binascii.hexlify(bytes(ciphertext)) returns another bytes object with the corresponding hexadecimal inside. binascii.hexlify(bytes(ciphertext))返回另一个bytes对象,其中包含相应的十六进制。 You're looking for bytes(ciphertext).hex() to get a string representation.您正在寻找bytes(ciphertext).hex()以获取字符串表示形式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM