0

I am currently trying to make a GUI for an app I am making for my friend. It encodes a string. That is irrelevant though. I need to use tkinter to make it so if you press a button it runs this code:

print "Welcome to the encoder"
print "[DO NOT USE CAPITAL LETTERS]"
# define the dictionary
encoder = {"a":"1", "b":"2", "c":"3", "d":"4", "e":"5", "f":"6", 
"g":"7", "h":"8", "i":"9", "j":"10", "k":"11", "l":"12", "m":"13", 
"n":"14", "o":"15", "p":"16", "q":"17", "r":"18", "s":"19", "t":"20", 
"u":"21", "v":"22", "w":"23", "x":"24", "y":"25", "z":"26"}

# take your input
Letter1 = raw_input ("Please input the first letter of the word: ")
Letter2 = raw_input ("Please input the second letter of the word: ")
Letter3 = raw_input ("Please input the third letter of the word: ")
Letter4 = raw_input ("Please input the fourth letter of the word: ")
Letter5 = raw_input ("Please input the fifth letter of the word: ")
Letter6 = raw_input ("Please input the sixth letter of the word: ")
Letter7 = raw_input ("Please input the seventh letter of the word: ")
Letter8 = raw_input ("Please input the eigth letter of the word: ")
Letter9 = raw_input ("Please input the ninth letter of the word: ")
Letter10 = raw_input ("Please input the tenth letter of the word: ")
Letter11 = raw_input ("Please input the eleventh letter of the word: ")
Letter12 = raw_input ("Please input the twelvth letter of the word: ")

# print out the encoded version
print encoder[Letter3] + " " + encoder[Letter2] + " " + encoder[Letter1] + "  " + encoder[Letter6] + " " + encoder[Letter5] + " " + encoder[Letter4] + "  " + encoder[Letter9] + " " + encoder[Letter8] + " " + encoder[Letter7] + "  " + encoder[Letter12] + " " + encoder[Letter11] + " " + encoder[Letter10]  
4
  • 1
    Where's the tkinter code? If you copy all this into a tkinter app, it'll run, but I assume you want GUI input rather than terminal input? Commented Mar 8, 2018 at 8:16
  • Also, why not just "Please input a twelve letter word"? Commented Mar 8, 2018 at 8:17
  • @cricket_007 becuase I need each letter to be a variable Commented Mar 8, 2018 at 8:20
  • You can index a string to get individual characters... Commented Mar 8, 2018 at 8:22

1 Answer 1

1

You should write a function

encoder = {"a":"1", "b":"2", "c":"3", "d":"4", "e":"5", "f":"6", 
"g":"7", "h":"8", "i":"9", "j":"10", "k":"11", "l":"12", "m":"13", 
"n":"14", "o":"15", "p":"16", "q":"17", "r":"18", "s":"19", "t":"20", 
"u":"21", "v":"22", "w":"23", "x":"24", "y":"25", "z":"26"}

def encode(letters):
    return " ".join(str(encoder.get(c, "")) for c in letters)

Then whatever tkinter code you write, call this function with either a list of letters or a lowercase string

Taking input from the user in Tkinter

For setting a tkinter label see this answer

Sign up to request clarification or add additional context in comments.

4 Comments

Yes, but my question was how to make the tkinter code
Sorry, but Stackoverflow isn't a code writing service. Please edit your question to include some attempt you've made. Then I'll update my answer
but i wasnt looking for the code given to me i was just looking for tips
That's hard to tell from your post. "Trying to make a GUI" sounds like you actually have tried something, but you didn't post it . Feel free to edit your question to rephrase

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.