By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,712 Members | 1,321 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,712 IT Pros & Developers. It's quick & easy.

How do I hide the answer given to a raw_input (and replace it with stars)?

P: 1
Hi!
Long story short; I'm doing a bit more advanced version of the classic game Hangman. You play with a friend and the thing is that you could see what word your friend had inserted in the raw_input.
Now I want to replace every letter in the chosen word into a star(*) so that you can't see the secret word anywere.
I'd appreciate it if you'd write the code in the answer.

Thanks in advance.
Jun 3 '12 #1
Share this Question
Share on Google+
1 Reply

bvdet
Expert Mod 2.5K+
P: 2,851
I don't know a way using raw_input, but you can do it with Tkinter. Example:
Expand|Select|Wrap|Line Numbers
  1. import Tkinter
  2.  
  3. textFont1 = ("Arial", 16, "normal")
  4.  
  5. class EntryWidget(Tkinter.Entry):
  6.     def __init__(self, master, initial=""):
  7.         Tkinter.Entry.__init__(self, master=master)
  8.         self.value = Tkinter.StringVar()
  9.         self.config(textvariable=self.value, width=20,
  10.                     relief="sunken", font=textFont1,
  11.                     bg="#eee", fg="#000",
  12.                     justify='center',
  13.                     show="*")
  14.         self.pack()
  15.         self.value.set(initial)
  16.  
  17. class App(Tkinter.Tk):
  18.     def __init__(self, title="Hidden Entry"):
  19.         Tkinter.Tk.__init__(self)
  20.         self.title(title)
  21.         self.w = EntryWidget(self)
  22.         self.mainloop()
  23.         self.value = self.w.value.get()
  24.  
  25. if __name__ == "__main__":
  26.     app = App()
  27.     print app.value
Jun 3 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.