Hi guys. This is my first post here and I've read through the forum quite a bit and can't wait to get more involved. So here is my main problem: getting my code to take the text I enter into an entry box to be recognized as a string so that I can continue to debug my program and finish it! I'll first paste the code and then show you the error message received as well. The two functions you see are all I can use (unless I want to add a decipher function for extra cred, which I do! Any help w/ that is appreciated).
I could use help for this as well:
Lines 27 and 31: my attempt at making my entry text into a str (didn't work)
Lines 44 and 45: just making sure my code works without using the GUI
Lines 46 - 48: trying to remove spaces and capitalize all letters of "message" and "key" but it does not work, therefore I went ahead and made them all caps/no spaces (for checking and debugging)
Line 49: Trying to make the keyword repeat to make it at least as long as the message to encode (but this was a failure as well)
Line 57: Why does this not undraw the rectangle?
Getting me headed in the right direction would do wonders!! Thanks so much.
## vigenere.py from graphics import * def encode(message, key): str.upper(message) str.upper(key) str.replace(message, " ", "") encodedMessage = "" for i in range(len(message)): newVal = ord(key[i]) - ord("A") letterVal = newVal + ord(message[i]) newLetter = chr(letterVal) encodedMessage = encodedMessage + newLetter return (encodedMessage) def main(): # GUI win = GraphWin("Vigenere Cipher", 600, 300) Text(Point(75,50), "Message to Encode").draw(win) message = Entry(Point(309, 50), 45) ## message.setText(string) message.draw(win) Text(Point(89,80), "Enter Keyword").draw(win) key = Entry(Point(216, 80), 18) ## key.setText(string) key.draw(win) button = Text(Point(120, 135), "Encode") button.draw(win) Rectangle(Point(80,155), Point(158, 110)).draw(win) Text(Point(76, 188), "Encoded Message").draw(win) output = Entry(Point(309, 188), 45) output.draw(win) # wait for mouse click win.getMouse() # encode phrase ## message = "ATTACKATDAWN" ## key = "CABCABCABCABCABCABCABCAB" ## str.replace(message, " ", "") ## str.upper(message) ## str.upper(key) ## key = key1 * (len(message)//(len(key1) + 1)) print(message, key) newMessage = encode(message, key) print(newMessage) # display output and remove button output.setText(newMessage) # wait for mouse click #Rectangle.undraw() button.undraw() Text(Point(300, 285), "Click to Close Window").draw(win) win.getMouse() # click to quit win.close() ## end of main main()
Edited by hbluthi: n/a