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)
self.username.focus()
# 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):
self.myparent.destroy()
# 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 ...')
lab0.pack()
root2 = Tk()
root2.geometry('400x300')
root2.title('Main Program window')
app2 = MyApp2(root2)
root2.mainloop()
# 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 ...')
self.lab1.pack()
# 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:
pass
for item in passwords :
if input2 == item:
self.correct()
else:
self.wrong()
## 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 ...')
self.lab.pack()
if root2 == Tk():
root = sys.exit()
# the root window
root = Tk()
root.title('Login window')
root.geometry('300x300')
app = MyApp(root)
root.mainloop()