如何从 Tkinter 中的条目获取输入以用于另一个 window 中使用的函数?

How do I get an input from an Entry in Tkinter to be used in a function to be used in another window?

# 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 的每个单独字符。我希望将此数组分配给 seperatedWord。

我也尝试过使用 .get() 将输入分配给另一个变量,然后尝试将其输入到函数 ciphering 中。

但是,我无法将密码输入输入到函数中。

我能得到一些关于如何做到这一点的帮助吗?

我在整个答案中添加了注释来解释我的更改

这应该有效:

# 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()