Advertisement
James_Slough

Nomination Randomizer v2.-1.1

Mar 7th, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.45 KB | None | 0 0
  1. # Importing libs
  2. from tkinter import *
  3. from tkinter import messagebox
  4. from tkinter import Toplevel
  5. import secrets
  6.  
  7. # Initialize Definitions
  8. def drawRandom():
  9.     # Get Input
  10.     names = NameArea.get("1.0", END).split("\n")
  11.     reasons = ReasonArea.get("1.0", END).split("\n")
  12.     nominators = NominatorArea.get("1.0", END).split("\n")
  13.     if (not(len(names) == len(reasons))) or (not(len(reasons) == len(nominators))):
  14.         messagebox.showerror("Dataset Error", "The amount of data in each column is not the same.")
  15.     else:
  16.         allPeople = []
  17.         for i in range(len(names)):
  18.             if i < len(names)-1: allPeople.append([names[i], reasons[i], nominators[i]])
  19.         ##print(allPeople)
  20.     # Get random choices
  21.     try: numberOfPeople = int(PeopleNumArea.get("1.0", END))
  22.     except: messagebox.showerror("Randomizer Error", "The amount of people to draw must be a number.")
  23.     finalPeople = []
  24.     for i in range(numberOfPeople):
  25.         finalPeople.append(allPeople.pop(allPeople.index(secrets.choice(allPeople))))  ### Write custom function later to tidy up code
  26.     # Result Window
  27.     output = ""
  28.     for person in finalPeople:
  29.         output+=("{person}: {reason} - {who}\n".format(person=person[0], reason=person[1], who=person[2]))
  30.     outFile = open("output.txt", "w")
  31.     outFile.write(output)
  32.     outFile.close()
  33.     resultWindow = Toplevel()
  34.     resultWindow.geometry("400x300")
  35.     resultWindow.iconbitmap("superMario.ico")
  36.     resultWindow.title("Results")
  37.     resultText = Text(resultWindow)
  38.     resultText.place(x=10, y=10, width=380, height=280)
  39.     resultText.insert(END, output)
  40.  
  41. # Initialize Tkinter
  42. window = Tk()
  43. window.title("Nomination Randomizer")
  44. window.iconbitmap("superMario.ico")
  45. width=600
  46. height=450
  47. window.geometry("{0}x{1}".format(width, height+20))
  48. sX=width/400
  49. sY=height/300
  50. window.resizable(False, False)
  51.  
  52. # Initialize Menu
  53. menu = Menu(window)
  54. dataset_menu = Menu(menu, tearoff=0)
  55. dataset_menu.add_command(label="Save")
  56. dataset_menu.add_command(label="Load")
  57. dataset_menu.add_command(label="Clear")
  58. menu.add_cascade(label="Dataset", menu=dataset_menu)
  59. window.config(menu=menu)
  60.  
  61. ##### Window Box #####
  62. # Input Boxes & Labels
  63. NameArea = Text(window)
  64. NameArea.place(x=10*sX, y=25*sY, height=200*sY, width=120*sX)
  65. NameArea.insert(END, "")
  66. NameAreaLabel = Label(window, text="Student name:", font="Arial {0}".format(int(8*sY)))
  67. NameAreaLabel.place(x=10*sX, y=2.5*sY)
  68.  
  69. ReasonArea = Text(window)
  70. ReasonArea.place(x=140*sX, y=25*sY, height=200*sY, width=120*sX)
  71. ReasonAreaLabel = Label(window, text="Reason for nomination:", font="Arial {0}".format(int(8*sY)))
  72. ReasonAreaLabel.place(x=140*sX, y=2.5*sY)
  73.  
  74. NominatorArea = Text(window)
  75. NominatorArea.place(x=270*sX, y=25*sY, height=200*sY, width=120*sX)
  76. NominatorAreaLabel = Label(window, text="Name of the nominator:", font="Arial {0}".format(int(8*sY)))
  77. NominatorAreaLabel.place(x=270*sX, y=2.5*sY)
  78.  
  79.  
  80. PeopleNumArea = Text(window, font="Arial {0}".format(int(10*sY)))
  81. PeopleNumArea.place(x=10*sX, y=245*sY, height=20*sY, width=380*sX)
  82. PeopleNumAreaLabel = Label(window, text="Number of people to draw:", font="Arial {0}".format(int(8*sY)))
  83. PeopleNumAreaLabel.place(x=10*sX, y=225*sY)
  84.  
  85. RandomizeButton = Button(window, text="Randomize", command=drawRandom)
  86. RandomizeButton.place(x=165*sX, y=270*sY, height=25*sY, width=70*sX)#height 25 width 70
  87. RandomizeButton['font'] = "Arial {0}".format(int(8*sY))
  88.  
  89. # Main loop to keep program running
  90. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement