【发布时间】:2021-06-01 05:08:21
【问题描述】:
所以我的想法是制作一个编码器,我的意思是当用户在称为文本的标签中写入例如“a”时,程序粘贴结果为 ex“}”等等。
问题是我是否必须为字母表中的每个字母和标签文本中的每个位置写“如果”我的意思是如果 user_code[0] 如果用户代码[1] 等等
import tkinter as tk
#making main window
root = tk.Tk()
root.title("Szyfrator")
root.geometry("600x300")
#getting text
def getting_Text():
user_code = text.get("1.0",'end-1c')
if user_code[0] == 'a' :
result.insert(tk.END, '[', 'big')
if user_code[0] == 'b':
result.insert(tk.END, ';', 'big')
#UX of the window
right_margin = tk.Frame(root)
right_margin.pack (side=tk.RIGHT, expand =tk.YES , fill=tk.BOTH)
left_margin = tk.Frame(root)
left_margin.pack(side=tk.LEFT, expand=tk.YES, fill=tk.BOTH)
#after clicking button function getting_text() is used
button = tk.Button( root , text = "Szyfruj", activebackground = "#FFFFFF", command=getting_Text)
button.pack( side = tk.TOP )
text=tk.Text(root, width=36, height=15 )
text.pack(side= tk.LEFT)
result= tk.Text(root, width=36, height=15 )
result.pack(side=tk.RIGHT)
# ):
root.mainloop()
【问题讨论】:
标签: python tkinter ttk encoder