Thread: Password Input

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    18
    Rep Power
    0

    Password Input


    I'm currently doing my coursework for computing, and currently I'm making a registration section.

    What I'm struggling with is getting the input entry to show Astrix's or circles.

    I'm using the module graphics.

    Code:
    from graphics import *
    import urllib.request, re
    
    def Login():
        LoginScreen = GraphWin("Login",300,100)
        file = open("users.csv","r")
        readfile = file.read()
        UsernameLabel = Text(Point(45,25),"Username: ")
        UsernameLabel.draw(LoginScreen)
        UsernameText = Entry(Point(158,25),16)
        UsernameText.draw(LoginScreen)
        username = ''
        LoginScreen.getMouse()
        LoginScreen.close()
    
    def Register():
        RegisterScreen = GraphWin("Register",300,150)
        UsernameRegLabel = Text(Point(45,25),"Username: ")
        UsernameRegLabel.draw(RegisterScreen)
        UsernameRegText = Entry(Point(158,25),16)
        UsernameRegText.draw(RegisterScreen)
        PasswordRegLabel = Text(Point(45,50),"Password: ")
        PasswordRegLabel.draw(RegisterScreen)
        PasswordRegText = Entry(Point(158,50),16)
        PasswordRegText.draw(RegisterScreen)
        RegisterScreen.getMouse()
        RegisterScreen.close()
    
    def GetMouse():
        p = MainWin.getMouse()
        x = p.getX()
        y = p.getY()
        print(x)
        print(y)
        if x>=197 and x<=260:
            if y>=230 and y<=250:
                Login()
        if x>=197 and x<=297:
            if y>=260 and y<=285:
                Register()
        
    def DrawBackground():
        return
        
    def DrawMenuItems():
        Main = Text(Point(300,200),"Main Menu")
        Main.setSize(32)
        Main.draw(MainWin)
        Login = Text(Point(228,240),"Login")
        Login.setSize(20)
        Login.draw(MainWin)
        Register = Text(Point(245,270),"Register")
        Register.setSize(20)
        Register.draw(MainWin)
    
    MainWin = GraphWin("Fantasy Football",600,600)
    
    DrawBackground()
    DrawMenuItems()
    while True:
        GetMouse()
    The bit I'm struggling with is
    Code:
    PasswordRegText = Entry(Point(158,50),16)
    PasswordRegText.draw(RegisterScreen)
    How do I get it to show circles or Asterixs?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,966
    Rep Power
    481
    asterisk.

    Use this symbol:

    In base 10 the unicode number is 9055.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    524
    Rep Power
    34
    If you want * in the box you can use setText. If you want each character entered to show as an asterisk, I don't think the graphics module can do that. Look at the "show=" option in Tkinter's entry box.
    Code:
    from Tkinter import *
    
    class PasswordGetter:
        def __init__(self):
            self.root = Tk()
            frame = Frame(self.root)
    
            lbl = Label(frame, text="Username ")
            lbl.grid(row=0, column=0, stick=N+E+S+W)
    
            self.user_name = StringVar()
            self.username_entry = Entry(frame, width=20, \
                                  textvariable=self.user_name)
            self.username_entry.grid(row=0, column=1, stick=N+E+S+W)
    
            lbl = Label(frame, text="Password ")
            lbl.grid(row=1, column=0, stick=N+E+S+W)
    
            self.passw = StringVar()
            self.password_entry = Entry(frame, show="*", width=20, textvariable=self.passw
            self.password_entry.grid(row=1, column=1, stick=N+E+S+W)
    
            login_button = Button(text="Login",
                                   command=self.buttonCallback)
     
            login_button = Button(text="Login",
                                   command=self.buttonCallback)
            login_button.grid(row=2, columnspan=2, stick=N+E+S+W)
    
            frame.grid(row=0, padx=2, pady=2, stick=N+E+S+W)
            self.root.mainloop()
    
    
        def buttonCallback(self):
                print self.user_name.get(), self.passw.get()
                self.root.destroy()
    
    if __name__ == "__main__":
        pg = PasswordGetter()
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    524
    Rep Power
    34
    You can use setText to set the text shown in an Entry box. If you want each character entered to display as an * I don't think the Graphics module can do that. Look at the "show=" option in the Tkinter entry box.
    Code:
    class PasswordGetter:
        def __init__(self):
            self.root = Tk()
            frame = Frame(self.root)
    
            lbl = Label(frame, text="Username ")
            lbl.grid(row=0, column=0, stick=N+E+S+W)
    
            self.user_name = StringVar()
            self.username_entry = Entry(frame, width=20, \
                                  textvariable=self.user_name)
            self.username_entry.grid(row=0, column=1, stick=N+E+S+W)
    
            lbl = Label(frame, text="Password ")
            lbl.grid(row=1, column=0, stick=N+E+S+W)
    
            self.passw = StringVar()
            self.password_entry = Entry(frame, show="*", width=20, textvariable=self.passw)
            self.password_entry.grid(row=1, column=1, stick=N+E+S+W)
    
            login_button = Button(text="Login",
                                   command=self.buttonCallback)
            login_button.grid(row=2, columnspan=2, stick=N+E+S+W)
    
            frame.grid(row=0, padx=2, pady=2, stick=N+E+S+W)
            self.root.mainloop()
    
    
        def buttonCallback(self):
                print self.user_name.get(), self.passw.get()
                self.root.destroy()
    
    if __name__ == "__main__":
        pg = PasswordGetter()

IMN logo majestic logo threadwatch logo seochat tools logo