# Imports the tkinter library.
from tkinter import *
# Pillow is a improved verison of PIL, stands for Python Image Library. Allows you to import image types like .jpg and .png
from PIL import ImageTk,Image
# Imports messagebox module from tkinter library.
from tkinter import messagebox
# Tk() helps to display the root window and manages all the other components of the tkinter application and assigns it to root.
root = Tk()
root.eval("tk::PlaceWindow . center")
# Renames the title of the tkinter window
root.title('d3cryptt')
def openCipher():
cipher = Toplevel()
cipher.title("decryptt - CIPHER")
cipherLabel = Label(cipher, text="cipher").pack()
cipherEntry = Entry(cipher, width=20, borderwidth=5).pack()
quitButton = Button(cipher, text="Exit Cipher", padx=10, pady=5, command=cipher.destroy).pack()
cipherButton = Button(cipher, text="Cipher", padx=10, pady=5, command=ciphering).pack()
def openDecipher():
decipher = Toplevel()
decipher.title("decryptt - DECIPHER")
decipherLabel = Label(decipher, text="decipher").pack()
quitButton = Button(decipher, text="Exit Decipher", padx=10, pady=5, command=decipher.destroy).pack()
# This is the function that is suppose to split the input from cipherEntry into individual characters in an array.
def ciphering(cipherEntry):
seperatedWord = list(cipherEntry.get())
cipherLabeling = Label(root, text = "You have inputted " seperatedWord.get()).pack()
appLogo = ImageTk.PhotoImage(Image.open("d3cryptt_logo_resized.png"))
appLogoLabel = Label(image=appLogo)
appLogoLabel.grid(row=0, column=0, columnspan=2)
cipherButton = Button(root, text=" Cipher ", padx=40, pady=20, command=openCipher).grid(row=1, column=0)
decipherButton = Button(root, text="Decipher", padx=40, pady=20, command=openDecipher).grid(row=1, column=1)
spacer1 = Label(root, text=" ", padx=10, pady=1).grid(row=4, column=1)
quitButton = Button(root, text="Exit d3cryptt", padx=10, pady=5, command=root.quit).grid(row=5, column=0, columnspan=2)
spacer2 = Label(root, text=" ", padx=10, pady=1).grid(row=6, column=1)
root.mainloop()
(這就是我到目前為止的全部內容,包括功能和輸入欄位)
這是我的加密應用程式的代碼。
我正在嘗試從 cipherEntry 獲取輸入以用于函式加密。然后,我想從 cipherEntry 創建一個陣列,該陣列使用 list() 保存 cipherEntry 的每個單獨字符。我希望將此陣列分配給separatedWord。
我還嘗試使用 .get() 將輸入分配給另一個變數,然后嘗試將其輸入到函式加密中。
但是,我無法將密碼條目的輸入放入函式中。
我能得到一些關于如何做到這一點的幫助嗎?
uj5u.com熱心網友回復:
我在整個答案中添加了注釋以解釋我的更改
這應該有效:
# Imports the tkinter library.
from tkinter import *
# Pillow is a improved verison of PIL, stands for Python Image Library. Allows you to import image types like .jpg and .png
from PIL import ImageTk,Image
# Imports messagebox module from tkinter library.
from tkinter import messagebox
# Tk() helps to display the root window and manages all the other components of the tkinter application and assigns it to root.
root = Tk()
root.eval("tk::PlaceWindow . center")
# Renames the title of the tkinter window
root.title('d3cryptt')
def openCipher():
cipher = Toplevel()
cipher.title("decryptt - CIPHER")
cipherLabel = Label(cipher, text="cipher").pack()
cipherEntry = Entry(cipher, width=20, borderwidth=5) #separating pack now allows you to use get() on this
cipherEntry.pack()
quitButton = Button(cipher, text="Exit Cipher", padx=10, pady=5, command=cipher.destroy).pack()
cipherButton = Button(cipher, text="Cipher", padx=10, pady=5, command=lambda:ciphering(cipherEntry.get())).pack() #lambda allows you to pass arguments to functions
def openDecipher():
decipher = Toplevel()
decipher.title("decryptt - DECIPHER")
decipherLabel = Label(decipher, text="decipher").pack()
quitButton = Button(decipher, text="Exit Decipher", padx=10, pady=5, command=decipher.destroy).pack()
# This is the function that is suppose to split the input from cipherEntry into individual characters in an array.
def ciphering(entry)
newTopLevel = Toplevel() #needed to add new label to
cipherLabeling = Label(newTopLevel, text = "You have inputted " entry).pack() #couldn’t add a list to string like that, nor use get() on a list, changed to just use the string
appLogo = ImageTk.PhotoImage(Image.open("d3cryptt_logo_resized.png"))
appLogoLabel = Label(image=appLogo)
appLogoLabel.grid(row=0, column=0, columnspan=2)
cipherButton = Button(root, text=" Cipher ", padx=40, pady=20, command=openCipher).grid(row=1, column=0)
decipherButton = Button(root, text="Decipher", padx=40, pady=20, command=openDecipher).grid(row=1, column=1)
spacer1 = Label(root, text=" ", padx=10, pady=1).grid(row=4, column=1)
quitButton = Button(root, text="Exit d3cryptt", padx=10, pady=5, command=root.quit).grid(row=5, column=0, columnspan=2)
spacer2 = Label(root, text=" ", padx=10, pady=1).grid(row=6, column=1)
root.mainloop()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/484860.html
上一篇:如何獲得陣列的10個最小數字?
下一篇:我怎樣才能得到這個陣列的總和?
