我是编码新手,我想编写一个 caeser 编码器。我已经准备好编码脚本,但我想把它放在一个 customtkinter 窗口中,我可以在其中写入编码器编号和文本,他给了我编码文本,我该如何开始,我创建了一个窗口,但我没有知道该做什么知道...
所以我知道我必须将编码器的这个脚本放在窗口中。
窗口创建器
import customtkinter
customtkinter.set_appearance_mode("dark") # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
app = customtkinter.CTk()
app.geometry("780x400")
app.title("CustomTkinter simple_example.py")
app.mainloop()
编码器
print("--CEASAR GELUMP--")
while True:
offset = input("GEBEN SIE DIE VERSCHIEBUNG AN: ")
if offset == "exit":
break
else:
offset = int(offset)
text = input("GEBEN SIE DEN ZU VERSCHLÜSSELNDEN TEXT EIN:\n")
output = ""
for i in text:
output+=chr(ord(i)+offset)
print(output)
print("ENDE")
你可以试试这个:
import tkinter as tk
app = tk.Tk()
app.geometry("780x400")
app.title("CustomTkinter Caesar Encoder")
def caesar_encode(offset, text):
output = ""
for i in text:
output += chr(ord(i) + offset)
return output
def on_encode():
offset = int(offset_entry.get())
text = text_entry.get()
encoded_text = caesar_encode(offset, text)
output_label.config(text=encoded_text)
offset_label = tk.Label(app, text="GEBEN SIE DIE VERSCHIEBUNG AN:")
offset_label.pack()
offset_entry = tk.Entry(app)
offset_entry.pack()
text_label = tk.Label(app, text="GEBEN SIE DEN ZU VERSCHLÜSSELNDEN TEXT EIN:")
text_label.pack()
text_entry = tk.Entry(app)
text_entry.pack()
encode_button = tk.Button(app, text="Encode", command=on_encode)
encode_button.pack()
output_label = tk.Label(app)
output_label.pack()
app.mainloop()