Tkinter and School Project

Melissa stlcardinalgirl at yahoo.com
Tue Mar 18 14:39:54 EST 2003


I need serious help on my project.

Here is what I am trying to make...An Address book.

I want you to be able to search by last name and have all possible
people to show up in the top list box.  Then you should be able to
click on the name and the information will appear in the bottom area.

Here is what I have so far.
I am very new at this and dont really know what I am doing.  I have it
"looking good", but is doesnt work.

Could someone PLEASE help me with this.



# This file is named melissaproject.pyw
from Tkinter import *
import tkMessageBox
from tkSimpleDialog import *
from tkFileDialog import *
from ScrolledText import *
import newrecord 
def openwindow (event):
    newrecord.dialog()
def closeit(event):
    root.destroy()
def findname(event):
    thelist1.delete(0,END)
    thename = findit.get()
    x = open("C:\\python22\\addyfile.txt","r")
    for y in x:
        q = y.split(",")
        if thename == q[1]:
            thelist1.insert(END,y)
    x.close()
def showit (event):
    person = thelist.get(ANCHOR)
    x = person.strip().split(',')
def readit(event):
    thelist.delete(0,END)
    x = open('c:\\python22\\addyfile.txt','r')
    for y in x:
        thelist.insert(END,y.strip())
    x.close()
root = Tk()
root.title("Easy Address Finder")
root.geometry('500x400')
b =Frame(root, bd = 3, bg='darkblue')
b.pack(side='top', fill = 'x')
findit = Entry(b, width=30)
find = Button(b, text = "SEARCH")
record = Button(b, text ="NEW RECORD")
record.bind('<ButtonRelease>',openwindow)
record.pack(side = "left", padx = 10, pady = 10)
find.bind('<ButtonRelease>',findname)
find.pack(side = "right", padx = 10, pady = 10)
findit.pack(side='right')
a = Frame(root, bd = 3,bg='darkblue')
a.pack(side='left', fill = 'y')
openfile = Button(a, text = "OPEN")
openfile.pack(side = "top", padx =10, pady =10)
close = Button(a, text = "EXIT")
close.pack(side = 'bottom',pady = 10, padx = 20)
close.bind("<ButtonRelease>",closeit)
openfile.bind("<ButtonRelease>",findname)
c = Frame(root, bd = 3, relief = 'groove')
c.pack(side='top', fill = 'x')
i =Frame(root)
thelist1 = Listbox(i,bg = 'white')
thelist1.pack(fill = 'both')
i.pack(side = 'top',fill = 'both',expand = 1)
thetext = ScrolledText(i)
thetext.pack(side = 'top',fill = 'both',expand =1)
root.mainloop()

------------------------------------------------------

# and this file is named newrecord.py
from Tkinter import *

def dialog():

    def closeit(event = None):
        win.destroy()
    
    def saveit(event):
        lblname = txtfirst.get()
        lbllast = txtlast.get()
        lbladd = txtadd.get()
        lblcity = txtcity.get()
        lblst = txtst.get()
        lblzip = txtzip.get()
        lblph = txtph.get()
        lblpx = txtpx.get()
        x = open('c:\\python22\\addyfile.txt','a')
        x.write(lblname + ',' + lbllast + ',' + lbladd + ',' + lblcity
+ ',' + lblst + ',' + lblzip + ',' + lblph + ',' + lblpx + '\n')
        x.close()
        txtfirst.delete(0,END)
        txtlast.delete(0,END)
        txtadd.delete(0,END)
        txtcity.delete(0,END)
        txtst.delete(0,END)
        txtzip.delete(0,END)
        txtph.delete(0,END)
        txtpx.delete(0,END)
        txtfirst.focus_set()
    win = Toplevel()
    win.geometry('400x230+100+100')
    d = Frame(win)
    txtfirst = Entry(d, width =40)
    lblname = Label(d, width = 15,text = 'First Name')
    lblname.pack(side = 'left',pady = 8)
    txtfirst.pack(side = 'left')
    d.pack(side = 'top',fill ='x')
    e = Frame(win)
    txtlast = Entry(e, width =40)
    lbllast = Label(e, width = 15,text = 'Last Name')
    lbllast.pack(side = 'left',pady = 8)
    txtlast.pack(side = 'left')
    e.pack(side = 'top',fill ='x')
    f = Frame(win)
    txtadd = Entry(f, width =40)
    lbladd = Label(f, width = 15,text = 'Street Address')
    lbladd.pack(side = 'left',pady = 8)
    txtadd.pack(side = 'left')
    f.pack(side = 'top',fill ='x')
    g = Frame(win)
    txtcity = Entry(g, width =16)
    lblcity = Label(g, width = 15,text = 'City')
    lblcity.pack(side = 'left',pady = 8)
    txtcity.pack(side = 'left')
    txtst = Entry(g, width =4)
    lblst = Label(g, width = 8,text = 'State')
    lblst.pack(side = 'left',pady = 8)
    txtst.pack(side = 'left')
    txtzip = Entry(g, width =8)
    lblzip = Label(g, width = 8,text = 'Zip')
    lblzip.pack(side = 'left',pady = 8)
    txtzip.pack(side = 'left')
    g.pack(side = 'top',fill ='x')
    h = Frame(win)
    txtph  = Entry(h, width =16)
    lblph = Label(h, width = 15,text = 'Phone')
    lblph.pack(side = 'left',pady = 5)
    txtph.pack(side = 'left')
    txtpx  = Entry(h, width =16)
    lblpx = Label(h, width = 10,text = 'Fax')
    lblpx.pack(side = 'left',pady = 8)
    txtpx.pack(side = 'left')
    h.pack(side = 'top',fill ='x')
    i = Frame(win)
    save = Button(i, text = "SAVE")
    save.bind('<ButtonRelease>',saveit)
    save.pack(side = "left", padx =75, pady =10)
    close = Button(i, text = "EXIT")
    close.pack(side = 'right',pady = 10, padx = 75)
    close.bind("<ButtonRelease>",closeit)
    i.pack(side = 'top',fill ='x')




More information about the Python-list mailing list