Hello everyone , as you can see i'm very beginer in python programming
1 mounth ago , i'm teaching my self from a python and tkinter book

i'm trying to write a program that opens the main window after entring the username and password

Problem 1:
The usernames and passwords list, a want to make couple of username_password
like : "mools" as username and "gang" as passwd , "melanie" as username , "toutain" as passwd ....

Problem 2:
i want to destroy the "login window" after opening the "main window"


Please Help fast as possible


i'm using linux/ubuntu11.04 (natty)
Python2.7 , Tkinter
this is the code , ==>

from Tkinter import *
import sys

# User names and passwords

usernames = ['melanie', 'mools','amazing']
passwords = ['toutain','gang','ball']

class MyApp:
        def __init__(self, parent):

                self.myparent = parent
                self.container1 = Frame(parent)
                self.container1.pack(side= 'top')

                # Label in the first

                self.label1 = Label(self.container1,
                                    text='                      \n'
                                    'Welcome to my Program \n'
                                    'Please enter the UserName and \n'
                                    'the password to continue\n'
                                    '                       ')
                self.label1.pack(side= 'top')

                # create a container for the username and its entry

                self.usercontainer = Frame(parent)
                self.usercontainer.pack(side= 'top')

                # create user name label                

                self.user = Label(self.usercontainer, text= 'UserName: ')
                self.user.pack(side= 'left', padx=10)

                # username Entry , making the focus to it
                self.username = Entry(parent, bg = 'white')
                self.username.pack(side= 'top', pady=5)

                # Creating the password container
                self.passcontainer = Frame(parent)
                self.passcontainer.pack(side= 'top')

                # password Label

                self.passe = Label(self.passcontainer, text= 'Password: ')
                self.passe.pack(side= 'top', padx=10)

                # password entry
                self.password = Entry(self.passcontainer, bg = 'white')
                self.password.pack(side= 'top', pady=10)

                # Creating the "OK" button               
                self.button1 = Button(self.passcontainer)
                self.button1.configure(text= "OK", fg= "white")
                self.button1.pack(side='left', padx=8, pady=8)

                # Binding the left mouse click button
                # to run the command "Check"
                self.button1.bind("<Button-1>", self.Check)
                self.button1.bind("<Return>", self.Check)

                # Creating the "EXIT" button
                self.button2 = Button(self.passcontainer)
                self.button2.configure(text= "Exit", fg= "white")
                self.button2.pack(side= 'right', padx=8, pady=8)
                # Binding it to the left mouse button
                #to run te command "Exit"
                self.button2.bind("<Button-1>", self.Exit)

        # Creating the function Exit, which will exit the program

        def Exit(self, event):

        # define the function correct witch should destroy the last window
        # and opens the new one ,

        # and this is a problem

        def correct(self):
                lab0 = Label(root, text= 'Correct Username and password \n'
                                  'Logging, please wait ...')
                root2 = Tk()
                root2.title('Main Program window')
                app2 = MyApp2(root2)

        # def the function wrong whitch will print wrong
        # when the passwd is wrong

        def wrong(self):
                self.lab1 = Label(root, text= 'Wrong Username or password \n'
                                  'Please try again ...')

        # Creating the function Check;
        # which will check if the username and pass are correct

        def Check(self, event):
                input = self.username.get()
                input2 = self.password.get()

                for item in usernames :
                        if input ==  item:
                for item in passwords :
                        if input2 == item:

## this is the second windows which i want to open and close the other

class MyApp2:
        def __init__(self, parent):
                self.myparent = parent
                self.containera = Frame(parent)
                self.containera.pack(side= 'top')

                self.lab = Label(self.containera, text= 'Welcome to the main \n'
                                 'program ...')
                if root2 == Tk():
                        root = sys.exit()

# the root window

root = Tk()
root.title('Login window')
app = MyApp(root)
5 Years
Discussion Span
Last Post by Enalicho

please i need response !!!

That isn't our problem, but yours. If you want a response, you need to make it easier to respond. What is the exact nature of the trouble your code is in? Does it

  • have a syntax error? What, exactly?
  • not run?
  • not run as expected?
  • do what you expect, but that isn't what you want?
  • something else?

Please read [thread=366794]this thread[/thread] and particularly notice the headings Keep the code short and sweet! and Don't give away code!. The first is for you, the second is why people won't write your homework for you.


ok soory ,
the problem is that my program don't run as expected

i want to destroy the "root window" after opening the "main window"

and creating couple of username:password to log in

That's all, thanks for ur replay


ok thanks , this website is very usefull ...
56 views and none come to answer me
thanks a lot

Votes + Comments
offensive comment

Alright, here we go -

usernames = ['melanie', 'mools','amazing']
passwords = ['toutain','gang','ball']

Don't do this. Use a dictionary, for example -

users = {'melanie':'toutain'}

Also, your choice of variable names is rather poor. I should be able to tell from the name what the object/method is and what it does. "MyApp" tells me little, as does "label1". Same applies to all of your program.

As to you problem -

what do you expect to happen when the user is correct? I expect a new instance of Tk to be created, then an instance of MyApp2, and for an instance of MyApp and MyApp2 to keep running. Protip - this isn't what you want, what you want is for MyApp to lay the path to MyApp2, but not create MyApp2, at least not in the form you're using, if you get what I mean ;) I hope this helps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.