Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using tkinter(GUI); Im trying to spawn an image with a button on python. However, when i press the caesar button im getting a _tkinter.TclError: cannot
Using tkinter(GUI); Im trying to spawn an image with a button on python. However, when i press the "caesar" button im getting a "_tkinter.TclError: cannot use geometry manager grid inside . which already has slaves managed by pack" error.
How do I fix this?
Below is my code:
from tkinter import * #main widgets we'll use are: Radiobutton, Label, Button, Entry, and Text. class CryptoApp: def __init__(self): window = Tk() #create a window window.title("CryptoApp") #set a title self.createWidgets(window) def createWidgets(self, window): frame1 = Frame(window) #add a frame inside the window with two radio buttons frame1.pack() #Create and add a frame to window self.v1 = IntVar() #create a radio button for the different choices caesarButton = Radiobutton(frame1, text="Ceasar Cipher", bg="blue", variable= self.v1, value=1, command=self.processRadiobutton) VigenereButton = Radiobutton(frame1, text="Vigenere Cipher", bg="yellow", variable=self.v1, value = 2, command=self.processRadiobutton) caesarButton.grid(row=1, column=1) VigenereButton.grid(row=1, column=2) #create Text Entries and buttons frame2 =Frame(window) frame2.pack() #create the nnecessary variables to tie to the field self.plaintext = StringVar() self.Ckey = IntVar() self.Vkey = StringVar() self.cipherText = StringVar() label = Label(frame2, text="enter your Plaintext: ") entryPlainText = Entry(frame2, show = "*", textvariable=self.plaintext, width = 15) label2 = Label(frame2, text = "enter your shared c secret key: ") entryKey = Entry(frame2, textvariable=self.Ckey) label4 = Label(frame2, text="enter your shared V secret key: ") entryKey2 = Entry(frame2, textvariable=self.Vkey) label3 = Label(frame2, text = "Enter your ciphertext: ") entryCipherText = Entry(frame2, textvariable=self.cipherText) btnEncrypt = Button(frame2, text="Encrypt", command=self.processEncryptButton) btnDecrypt = Button(frame2, text="Decrypt", command=self.processDecryptButton) * ****this is the part thats giving me trouble******** button1 = Button(frame2, text="Caesar", fg="black", command=self.shuffle) button1.grid(column=4, row=4) **************************************************** label.grid(row=2, column=1) entryPlainText.grid(row=2, column=2) label2.grid(row=2, column=3) entryKey.grid(row=2, column=4) label4.grid(row=3, column=3) entryKey2.grid(row=3, column=4) label3.grid(row=3, column=1) entryCipherText.grid(row=3, column=2) btnEncrypt.grid(row=4, column=2) btnDecrypt.grid(row=4, column=3) #add a text self.text = Text(window) self.text.pack() self.text.insert(END, "your cipherText will appear below here: ") window.mainloop() # create an event loop def processRadiobutton(): print(("Ceaser Cipher" if self.v1.get() == 1 else "Substitution Cipher") + "is selected") print.self.v1 def processEncryptButton(self): print("Your plaintext is: " + self.plaintext.get()) #this is caeser cipher if (self.v1.get() == 1): for p in self.plaintext.get(): c = (ord(p) + self.Ckey.get()) #function ord() returns the ascii code of a character self.text.insert(END, chr(c)) #function chr() returns the character of an ascii code else: keyvalue = self.Vkey.get() index = 0 for i in self.plaintext.get(): v = (ord(i) + ord(keyvalue[index])) index = index + 1 if (index == len(keyvalue)): index = 0 self.text.insert(END, chr(v)) def processDecryptButton(self): self.text.insert(END, " Your recovered plaintext is: ") if (self.v1.get() == 1): for c in self.cipherText.get(): p = (ord(c) - self.Ckey.get()) #function ord() returns the ascii code of a character self.text.insert(END, chr(p)) #function chr() returns the character of an ascii code else: keyvalue = self.Vkey.get() index = 0 for i in self.cipherText.get(): v = (ord(i) - ord(keyvalue[index])) index = index + 1 if (index == len(keyvalue)): index = 0 self.text.insert(END, chr(v)) *****************THis is what im using to spawn the image******************************* def shuffle(self): img = PhotoImage(file= "1.gif") label1 = Label(image=img) label1.Photo = img label1.grid(column=6, row=4, sticky=N + S + E + W) ******************************************* #main code ############################### CryptoApp()
output:
CryptoApp Ceasar Cipher Vigenere Cipher enter your Plaintext: enter your shared c secret key: 0 Enter your ciphertext: enter your shared V secret key: Encrypt Decrypt your cipherText will appear below here: Caesar Run: G dil OL 6 Crypto2 "C:\Users \Desktop\CryptoApp\venv\Scripts\python.exe" "C:/Users/ /Desktop/CryptoApp/Crypto2.py" Exception in Tkinter callback Traceback (most recent call last): File "C:\Users \AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__ return self.func(*args) File "C:/Users/ /Desktop/CryptoApp/Crypto2.py", line 133, in shuffle Label1.grid(column=2, row=0, sticky=N + S + E + W) File "C:\Users\ \AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 2484, in grid_configure self.tk.call( tkinter. TelError: cannot use geometry manager grid inside which already has slaves managed by pack . CryptoApp Ceasar Cipher Vigenere Cipher enter your Plaintext: enter your shared c secret key: 0 Enter your ciphertext: enter your shared V secret key: Encrypt Decrypt your cipherText will appear below here: Caesar Run: G dil OL 6 Crypto2 "C:\Users \Desktop\CryptoApp\venv\Scripts\python.exe" "C:/Users/ /Desktop/CryptoApp/Crypto2.py" Exception in Tkinter callback Traceback (most recent call last): File "C:\Users \AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__ return self.func(*args) File "C:/Users/ /Desktop/CryptoApp/Crypto2.py", line 133, in shuffle Label1.grid(column=2, row=0, sticky=N + S + E + W) File "C:\Users\ \AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 2484, in grid_configure self.tk.call( tkinter. TelError: cannot use geometry manager grid inside which already has slaves managed by packStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started