[英]I am getting { } on the end of my output. What is causing this and how do I remove it?
我正在尝试一个简单的 gui,它使用同一 window 中的“秘密号码”/密钥标识符对消息进行加密和解密,以获得乐趣。 到目前为止,它有效,我对此感到非常满意。 我唯一的问题是我在 crypt() function 中得到了 output 返回我想要的内容,然后是 {}。 使用普通的 print() function,我没有这个问题。 但是,使用 GUI 可以。 我想这是 package tkinter 这样做吗?
我的代码:
from tkinter import *
import tkinter.messagebox
def crypt():
so = int(nu1.get())
inp = str(nu2.get().upper())
old_dic = {chr(i): i * (int(so)+int(so))for i in range(ord("A"), ord("A") + 26)}
if len(inp) >= 1:
bit = list(inp)
spell = list(map(old_dic.get, bit))
spell = spell[::-1]
ans1 = (*spell, "")
blank4.insert(0, ans1)
else:
print("Improper input.")
main = Tk()
Label(main, text = "Enter secret number:").grid(row=0)
Label(main, text = "Cryptify:").grid(row=1)
Label(main, text = "Encrypted output:").grid(row=2)
Button(main, text='Show', command=crypt).grid(row=3, column=1, sticky=W, pady=4)
nu1 = Entry(main)
nu2 = Entry(main)
blank4 = Entry(main)
nu1.grid(row=0, column=1)
nu2.grid(row=1, column=1)
blank4.grid(row=2, column=1)
mainloop()
Output 我得到的加密看起来像这样:
密码:45
加密:你好
加密 Output:7110 6840 6840 6210 6480 {}
Output 应如下所示:
密码:45
加密:你好
加密 Output:7110 6840 6840 6210 6480
原因很简单, tkinter
使用tcl
,它不知道 python list
或tuple
是什么,它是tcl
读取元组/列表的方式,将其放入{}
中,就像您注意到的那样,所以将其转换为字符串,例如:
ans1 = (*map(str,spell), "")
blank4.insert(0, ' '.join(ans1))
同样,对所有看到大括号的地方都这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.