Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. from tkinter import *
  2.  
  3. window = Tk()
  4. window.geometry("400x550")
  5. window.configure(background = "black")
  6. window.title("My Attendance Program")
  7. dic = {}
  8. files = open("filehandling.txt", 'w+')
  9. files.close()
  10. ############declaration of functions:
  11.  
  12. def submit_subject():#function works fine
  13. files = open("filehandling.txt", 'r+')
  14. entered_subject = subject_val.get()
  15. output1.delete(0.0, END)
  16. for line in files:
  17. splitline = line.split()
  18. dic["{}".format(splitline[0])] = int(splitline[1])
  19. if entered_subject == "":
  20. output1.insert(END, "don't enter null string")
  21. elif entered_subject in dic.keys():
  22. output1.insert(END, "subject already exists")
  23. else:
  24. files.writelines(entered_subject+" "+"0"+"n")
  25. output1.insert(END, "subject "+ entered_subject+ " added")
  26. files.close()
  27.  
  28. def view_subject():
  29. files = open("filehandling.txt", 'r+')
  30. output2.delete(0.0, END)
  31. for line in files:
  32. splitline = line.split()
  33. dic["{}".format(splitline[0])] = int(splitline[1])
  34. output2.insert(END, ', '.join(dic.keys()))
  35. files.close()
  36.  
  37. def donothing():
  38. print("hello")
  39.  
  40. def increment_in_file(strings):
  41. print(strings +" has been updated")
  42. files = open("filehandling.txt", 'r+')
  43. for line in files:
  44. splitline = line.split()
  45. dic["{}".format(splitline[0])] = int(splitline[1])
  46. files.close()
  47. files = open("filehandling.txt", 'w')
  48. for keys in dic:
  49. if keys == strings:
  50. files.writelines(keys + " " + "{}n".format(dic[keys] + 1))
  51. else:
  52. files.writelines(keys + " " + "{}n".format(dic[keys]))
  53. files.close()
  54.  
  55.  
  56. #####################################function that is causing problem
  57. def menubutton():
  58. but = Menubutton(window, text = "choose subject")
  59. but.grid(row = 7, column = 0, sticky = W)
  60. but.menu = Menu(but)
  61. but["menu"] = but.menu
  62. files = open("filehandling.txt", 'r+')
  63. output2.delete(0.0, END)
  64. for line in files:
  65. splitline = line.split()
  66. dic["{}".format(splitline[0])] = int(splitline[1])
  67. but.menu.add_command(label = "{}".format(splitline[0]), command = lambda: increment_in_file("{}".format(splitline[0])))
  68. files.close()
  69. # print(dic)
  70.  
  71.  
  72.  
  73. ###############increment_in_file("{}".format(splitline[0]))
  74.  
  75. #ask for entry of subject row 0 and 1
  76. Label(window, bg = "black", fg = "yellow", text = "Enter subject",anchor = W, width = 40).grid(row = 0, column = 0, sticky = W)
  77. #entry window
  78. subject_val = Entry(window, width = 40)
  79. subject_val.grid(row = 1, column = 0, sticky = W)
  80.  
  81. #button for submission of subject along with result row 2 and 3
  82. Button(window, text = "Submit", width = 8, command = submit_subject).grid(row = 2, column = 0, sticky = W)
  83. output1 = Text(window, wrap = WORD, width = 40, height = 1)
  84. output1.grid(row = 3, column = 0, sticky = W)
  85.  
  86. #button and output for the entered subjects row 4 and 5
  87. Button(window, text = "View Subject", width = 15, height = 1, command = view_subject).grid(row = 4, column = 0, sticky = W)
  88. output2 = Text(window, wrap = WORD, width = 40, height = 3)
  89. output2.grid(row = 5, column = 0, sticky = W)
  90.  
  91.  
  92.  
  93. #button to mark attendance row 6 and 7
  94. Button(window, text = "Mark attendance", width = 15, height = 1, command = menubutton).grid(row = 6, column = 0, sticky = W)
  95.  
  96.  
  97.  
  98.  
  99.  
  100. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement