Hi, this is my code for Python:

granted = False
for count in range(10):
    password = raw_input('Please enter a password: ')
    if password == 'thepassword':
        granted = True
        break
    print 'You have entered invalid password %i times.' % (count+1)

if granted:
    print 'Access Granted'
    raw_input('Press ENTER to continue...\n')
else:
    print 'Access Denied. Please retry.'
    raw_input('Press ENTER to continue...\n')

I want to use a GUI like this:

import wx

class mainclass(wx.Frame):

    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,'Password Program', size=(300,300))
        panel=wx.Panel(self)
        
        box=wx.TextEntryDialog(None, 'Please type your password:','Password')
        if box.ShowModal()==wx.ID_OK:
            answer=box.GetValue()
        
if __name__=='__main__':
    app=wx.PySimpleApp()
    frame=mikey(parent=None,id=-1)
    frame.Show()
    app.MainLoop()

If you try the second code, it will pop up a password box, then when you press OK it will close and the main program window will open.
I want it so when you type the correct password, the main program window opens, and if not, the 'retry' text shows.

Help?

Recommended Answers

All 2 Replies

Something like this should work:

# check for password entry, close application if not correct

import wx

class MyClass(wx.Frame):

    def __init__(self, parent=None, id=-1):
        wx.Frame.__init__(self, parent, id, 'Password Program', size=(300,300))
        panel = wx.Panel(self)
        
        box = wx.TextEntryDialog(None, 'Please type your password:','Password')
        if box.ShowModal() == wx.ID_OK:
            answer = box.GetValue()
        # check password, you want ot use 'rot13' to mask password
        if answer != 'password':
            # message to user
            self.SetTitle('%s is incorrect password!' % answer)
            # wait 3 seconds, then close the app
            # or call dialog box again
            wx.FutureCall(3000, self.Destroy)
        # here goes the code to go on ...
        
        
if __name__=='__main__':
    app = wx.App(0)
    frame = MyClass()
    frame.Show()
    app.MainLoop()

Check this out.
1. You will need 2 frame for that. or 1 dialog box and a frame. Its your choice.
2. overide the wx.App() and in the oninit method, call the dialog box/frame.
3. Dialog box/frame must be a main frame. Once the check is ok..., the the dialog box/frame should call the second frame which is the operational window and hide the dialog box/frame password check.

4. If the password is not correct,,, then re ask for the password.

Hope you got the idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.