Guest User

Untitled

a guest
Nov 24th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. # The purpose of this program is to produce a GUI that acts as a 'contacts
  2. #info retriever', when a 'contact' 'button' is clicked it displays the contact
  3. #information of that person
  4.  
  5.  
  6.  
  7.  
  8. # Make a 'dictionary' containing contact info
  9.  
  10. contacts = { 1: {"Name" : "Max", "Address" : "18 Fake Street, Hollywood", "Mobile" : "07542564872"},
  11. 2: {"Name" : "Brian", "Address" : "17 Fake Boulevard, Hollywood", "Mobile" : "07895465231"},
  12. 3: {"Name" : "Sally", "Address" : "19 Hill Valley, Hollywood", "Mobile" : "07956423145"},
  13. 4: {"Name" : "Steve", "Address" : "22 Fake House, Hollywood", "Mobile" : "07456213895"},
  14. 5: {"Name" : "Sara", "Address" : "46 Fake Drive, Hollywood", "Mobile" : "07652348192"},
  15. 6: {"Name" : "Kevin", "Address" : "18 Labyrinth Avenue, Hollywood", "Mobile" : "07563245196"},
  16. 7: {"Name" : "Paula", "Address" : "38 Fake Drive, Hollywood", "Mobile" : "07354695488"},
  17. 8: {"Name" : "Dave", "Address" : "Haystack Farm, Hollywood", "Mobile" : "07854623198"},
  18. 9: {"Name" : "Mary", "Address" : "Fake Valley, CA", "Mobile" : "07564289315"},
  19. 10:{"Name" : "Anastasia", "Address" : "Some Street, Hollywood", "Mobile" : "07546321595"}}
  20.  
  21. # Import 'GUI creation' module
  22.  
  23. import tkinter
  24.  
  25. # Create a 'window'
  26.  
  27. window = tkinter.Tk()
  28.  
  29. # Give the window a 'title'
  30.  
  31. window.title("Phonebook")
  32.  
  33. # Import an 'ico' file for icon
  34.  
  35. window.wm_iconbitmap("Moon Full.ico")
  36.  
  37.  
  38. # Create a 'label' that displays opening instruction message at top
  39.  
  40. lbl = tkinter.Label(window, text="Click a contact to show their details:")
  41.  
  42. # 'Pack' the 'label'
  43.  
  44. lbl.pack()
  45.  
  46.  
  47.  
  48. # A 'function' for the 'reconfiguration' of 'labels' (changing their output)
  49.  
  50. def changeLabel():
  51. lbl2.configure(text="Details for " + str(btn))
  52.  
  53.  
  54.  
  55. # 'Dynamically create' 'buttons' using a 'for loop' as so
  56.  
  57. for i in contacts:
  58.  
  59. #creates 'button' for what ever 'sub dictionary' (contact) the 'loop'
  60. #is currently on
  61.  
  62. btn = tkinter.Button(window, text=contacts [i] ["Name"], command=changeLabel)
  63.  
  64. #'pack' the 'button'
  65.  
  66. btn.pack()
  67.  
  68.  
  69.  
  70. # Create a 'label' to display 'who the info belongs to'
  71. lbl2 = tkinter.Label(window, text="No contact selected")
  72.  
  73. # Pack label
  74. lbl2.pack()
  75.  
  76. # Draw the 'window', engage program
  77. window.mainloop()
Add Comment
Please, Sign In to add comment