我在删除'labelresult'文本框中的文本时遇到问题。我试图使用我在Stack Overflow上找到的一些解决方案,但它们不起作用。任何帮助都将很高兴。
from tkinter import *
from random import randint
def encrypt():
encrypted = ""
encCode1 = str(encCode.get())
try:
encNum1 = int(encNum.get())
except ValueError:
labelresult = Label(myGUI, text="You did not use a number please try again").grid(row=7, column=2)
if (encNum1 == 0):
encNum1 = randint(-38,4)
for letter in encCode1:
if letter == " ":
encrypted += " "
else:
encrypted += chr(ord(letter)+encNum1)
labelresult = Label(myGUI, text=encrypted).grid(row=7, column=2)
myGUI=Tk()
myGUI.geometry("700x300")
myGUI.title("Encrypter/Decrypter")
encCode=StringVar()
encNum=StringVar()
label1=Label(myGUI,text="Use the two boxes under this text to Encrypt", fg="red").grid(row=0,column=2)
label2=Label(myGUI,text="Enter the code to be encrypted").grid(row=2,column=0)
label3=Label(myGUI,text="Enter a number between -38 and 4 to encrypt with").grid(row=3,column=0)
myn=Entry(myGUI,textvariable=encCode).grid(row=2, column=2)
mys=Entry(myGUI,textvariable=encNum).grid(row=3, column=2)
button1=Button(myGUI,text="Calculate Encrypted Code",command=encrypt).grid(row=4,column=0)
myGUI.mainloop()