Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The purpose of this program is to produce a GUI that acts as a 'contacts
- #info retriever', when a 'contact' 'button' is clicked it displays the contact
- #information of that person
- # Make a 'dictionary' containing contact info
- contacts = { 1: {"Name" : "Max", "Address" : "18 Fake Street, Hollywood", "Mobile" : "07542564872"},
- 2: {"Name" : "Brian", "Address" : "17 Fake Boulevard, Hollywood", "Mobile" : "07895465231"},
- 3: {"Name" : "Sally", "Address" : "19 Hill Valley, Hollywood", "Mobile" : "07956423145"},
- 4: {"Name" : "Steve", "Address" : "22 Fake House, Hollywood", "Mobile" : "07456213895"},
- 5: {"Name" : "Sara", "Address" : "46 Fake Drive, Hollywood", "Mobile" : "07652348192"},
- 6: {"Name" : "Kevin", "Address" : "18 Labyrinth Avenue, Hollywood", "Mobile" : "07563245196"},
- 7: {"Name" : "Paula", "Address" : "38 Fake Drive, Hollywood", "Mobile" : "07354695488"},
- 8: {"Name" : "Dave", "Address" : "Haystack Farm, Hollywood", "Mobile" : "07854623198"},
- 9: {"Name" : "Mary", "Address" : "Fake Valley, CA", "Mobile" : "07564289315"},
- 10:{"Name" : "Anastasia", "Address" : "Some Street, Hollywood", "Mobile" : "07546321595"}}
- # Import 'GUI creation' module
- import tkinter
- # Create a 'window'
- window = tkinter.Tk()
- # Give the window a 'title'
- window.title("Phonebook")
- # Import an 'ico' file for icon
- window.wm_iconbitmap("Moon Full.ico")
- # Create a 'label' that displays opening instruction message at top
- lbl = tkinter.Label(window, text="Click a contact to show their details:")
- # 'Pack' the 'label'
- lbl.pack()
- # A 'function' for the 'reconfiguration' of 'labels' (changing their output)
- def changeLabel():
- lbl2.configure(text="Details for " + str(btn))
- # 'Dynamically create' 'buttons' using a 'for loop' as so
- for i in contacts:
- #creates 'button' for what ever 'sub dictionary' (contact) the 'loop'
- #is currently on
- btn = tkinter.Button(window, text=contacts [i] ["Name"], command=changeLabel)
- #'pack' the 'button'
- btn.pack()
- # Create a 'label' to display 'who the info belongs to'
- lbl2 = tkinter.Label(window, text="No contact selected")
- # Pack label
- lbl2.pack()
- # Draw the 'window', engage program
- window.mainloop()
Add Comment
Please, Sign In to add comment