Tkinter and School Project
Eric Brunel
eric.brunel at pragmadev.com
Wed Mar 19 04:23:33 EST 2003
Melissa wrote:
> 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.
You were quite close:
> # 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)
I think you want theList1 and not theList here.
> x = open('c:\\python22\\addyfile.txt','r')
> for y in x:
> thelist.insert(END,y.strip())
Same here.
> 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)
This should work, but it's not the way things are usually done. Use preferably
the "command" option in buttons:
record = Button(b, text ="NEW RECORD", command=openwindow)
But note with this option, the "event" parameter in your functions above is not
needed anymore. So you may remove it or give a default value (e.g. "def
openwindow (event=None)").
> 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)
Don't you want "readit" instead of "findname" here? And same thing: you should
use the "command" option on button "openfile".
> 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()
[snip apparently working code for newrecord.py]
Please note I work with Python 2.1, so I had to change things a bit to make
things work, especially because I don't have nested scopes. So you may have to
change a few more things.
HTH
--
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
More information about the Python-list
mailing list