Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.12 KB | None | 0 0
  1. import tkinter
  2. import time #import tkinter and time modules
  3. from tkinter import *
  4. def attendance(): #define attendance function
  5.     aWindow = Toplevel(root) #create a new window with root window as parent
  6.     aWindow.title("Attendance Details") #title for new window
  7.     def validate(): #inside the attendance function define a validation function for the validate button
  8.         global session1
  9.         global session2
  10.         global session3
  11.         global session4
  12.         #make the adult and child variables global so they can be used in the other functions
  13.         session1 = [int(entAdult1.get()),int(entChild1.get())]
  14.         session2 = [int(entAdult2.get()),int(entChild2.get())]
  15.         session3 = [int(entAdult3.get()),int(entChild3.get())]
  16.         session4 = [int(entAdult4.get()),int(entChild4.get())] #these are arrays that only exist to fill task requirements, but I suppose it saves a few lines of code anway
  17.         #makes the final variables the text from the child and adult entry classes
  18.         if session1[0] >= -1 and session1[1] >= -1 and session2[0] >= -1 and session2[1] >= -1 and session3[0] >= -1 and session3[1] >= -1 and session4[0] >= -1 and session1[1] >= -1: #checks to see if the values are above zero
  19.             valid.config(text=("CONFIRMED")) #if they are change the valid lable text to CONFIRMED
  20.             btnCloseA.config(state="normal") #makes the exit button clickable
  21.             b2.config(state="normal") #enables the revenue button on the mainwindow to be clickable
  22.         else: #if the values are below zero then:
  23.             valid.config(text="please enter numbers greater than or equal to zero") #makes the valid label complain
  24.             btnCloseA.config(state="disabled") #if the exit button is clickable makes it unclickable
  25.     def validate2(event): #inside the attendance function define a validation function for the validate button
  26.         global session1
  27.         global session2
  28.         global session3
  29.         global session4
  30.         #make the adult and child variables global so they can be used in the other functions
  31.         session1 = [int(entAdult1.get()),int(entChild1.get())]
  32.         session2 = [int(entAdult2.get()),int(entChild2.get())]
  33.         session3 = [int(entAdult3.get()),int(entChild3.get())]
  34.         session4 = [int(entAdult4.get()),int(entChild4.get())] #these are arrays that only exist to fill task requirements, but I suppose it saves a few lines of code anway
  35.         #makes the final variables the text from the child and adult entry classes
  36.         if session1[0] >= -1 and session1[1] >= -1 and session2[0] >= -1 and session2[1] >= -1 and session3[0] >= -1 and session3[1] >= -1 and session4[0] >= -1 and session1[1] >= -1: #checks to see if the values are above zero
  37.             valid.config(text=("CONFIRMED")) #if they are change the valid lable text to CONFIRMED
  38.             btnCloseA.config(state="normal") #makes the exit button clickable
  39.             b2.config(state="normal") #enables the revenue button on the mainwindow to be clickable
  40.         else: #if the values are below zero then:
  41.             valid.config(text="please enter numbers greater than or equal to zero") #makes the valid label complain
  42.             btnCloseA.config(state="disabled") #if the exit button is clickable makes it unclickable
  43.    
  44.     adult1 = IntVar()
  45.     child1 = IntVar()
  46.     adult2 = IntVar()
  47.     child2 = IntVar()
  48.     adult3 = IntVar()
  49.     child3 = IntVar()
  50.     adult4 = IntVar()
  51.     child4 = IntVar()
  52.  
  53.     def clearAdult1(event):
  54.         entAdult1.selection_range(0,END)
  55.     def clearAdult2(event):
  56.         entAdult2.selection_range(0,END)
  57.     def clearAdult3(event):
  58.         entAdult3.selection_range(0,END)
  59.     def clearAdult4(event):
  60.         entAdult4.selection_range(0,END)
  61.     def clearChild1(event):
  62.         entChild1.selection_range(0,END)
  63.     def clearChild2(event):
  64.         entChild2.selection_range(0,END)
  65.     def clearChild3(event):
  66.         entChild3.selection_range(0,END)
  67.     def clearChild4(event):
  68.         entChild4.selection_range(0,END) #all the stuff that makes it so you only have to click once instead of twice to select, enjoy it
  69.    
  70.     #makes the adult and child entries integer values
  71.     labAdult1 = Label(aWindow, text="S1 Adults:")
  72.     labAdult1.grid(row=0, sticky=W)
  73.     labChild1 = Label(aWindow, text="S1 Children:")
  74.     labChild1.grid(row=1, sticky=W) #creates and positions the text
  75.     entAdult1 = Entry(aWindow, validate="key", textvariable=adult1)
  76.     entAdult1.grid(row=0, column=1)
  77.     entChild1 = Entry(aWindow, validate="key", textvariable=child1)
  78.     entChild1.grid(row=1, column=1) #creates and positions the entries
  79.     Label(aWindow, text=" ").grid(row=2)
  80.     entAdult1.bind("<FocusIn>",clearAdult1)
  81.     entChild1.bind("<FocusIn>",clearChild1) #more stuff that makes the select thing work when the entry is given focus
  82.    
  83.     labAdult2 = Label(aWindow, text="S2 Adults:")
  84.     labAdult2.grid(row=3, sticky=W)
  85.     labChild2 = Label(aWindow, text="S2 Children:")
  86.     labChild2.grid(row=4, sticky=W) #creates and positions the text
  87.     entAdult2 = Entry(aWindow, validate="key", textvariable=adult2)
  88.     entAdult2.grid(row=3, column=1)
  89.     entChild2 = Entry(aWindow, validate="key", textvariable=child2)
  90.     entChild2.grid(row=4, column=1) #creates and positions the entries
  91.     Label(aWindow, text=" ").grid(row=5)
  92.     entAdult2.bind("<FocusIn>",clearAdult2)
  93.     entChild2.bind("<FocusIn>",clearChild2)
  94.    
  95.     labAdult3 = Label(aWindow, text="S3 Adults:")
  96.     labAdult3.grid(row=6, sticky=W)
  97.     labChild3 = Label(aWindow, text="S3 Children:")
  98.     labChild3.grid(row=7, sticky=W) #creates and positions the text
  99.     entAdult3 = Entry(aWindow, validate="key", textvariable=adult3)
  100.     entAdult3.grid(row=6, column=1)
  101.     entChild3 = Entry(aWindow, validate="key", textvariable=child3)
  102.     entChild3.grid(row=7, column=1) #creates and positions the entries
  103.     Label(aWindow, text=" ").grid(row=8)
  104.     entAdult3.bind("<FocusIn>",clearAdult3)
  105.     entChild3.bind("<FocusIn>",clearChild3)
  106.  
  107.     labAdult4 = Label(aWindow, text="S4 Adults:")
  108.     labAdult4.grid(row=9, sticky=W)
  109.     labChild4 = Label(aWindow, text="S5 Children:")
  110.     labChild4.grid(row=10, sticky=W) #creates and positions the text
  111.     entAdult4 = Entry(aWindow, validate="key", textvariable=adult4)
  112.     entAdult4.grid(row=9, column=1)
  113.     entChild4 = Entry(aWindow, validate="key", textvariable=child4)
  114.     entChild4.grid(row=10, column=1) #creates and positions the entries
  115.     Label(aWindow, text=" ").grid(row=11)
  116.     entAdult4.bind("<FocusIn>",clearAdult4)
  117.     entChild4.bind("<FocusIn>",clearChild4)
  118.    
  119.     btnCloseA = Button(aWindow, text="EXIT", fg="red",state = DISABLED, command = aWindow.destroy, padx = 30,)
  120.     btnCloseA.grid(row=0 ,column=2, rowspan = 2, columnspan=2, sticky=N)
  121.     btnValid = Button(aWindow, text="Validate", state = NORMAL, padx = 20, command=validate)
  122.     btnValid.grid(row=1, column=2, rowspan = 2, columnspan=2, sticky=S) #creates and positions the buttons
  123.     valid = Label(aWindow, text = "STANDBY...")
  124.     valid.grid(row=12, columnspan=99, sticky=W) #creates and positions the valid text
  125.     aWindow.bind("<Return>",validate2)
  126.  
  127. def revenue(): #create the revenue function
  128.     bWindow = Toplevel(root) #new window
  129.     labDisplay1 = Label(bWindow, text=("adult total: "+str(session1[0]+session2[0]+session3[0]+session4[0])+" child total: "+str(session1[1]+session2[1]+session3[1]+session4[1]))) #label that displays the adult and child values defined in the other function
  130.     labDisplay1.grid(row=0)
  131.    
  132.     labPriceA = Label(bWindow, text = "Adult price: $15")
  133.     labPriceA.grid(row=1)
  134.     labPriceB = Label(bWindow, text = "Child price: $8")
  135.     labPriceB.grid(row=2)
  136.    
  137.     labResult1 = Label(bWindow, text = ("Money made S1: $" + str((session1[0]*15)+(session1[1]*8)))) #does the calculations
  138.     labResult1.grid(row=3)
  139.     Label(bWindow, text = " ").grid(row=4)
  140.  
  141.     labResult2 = Label(bWindow, text = ("Money made S2: $" + str((session2[0]*15)+(session2[1]*8)))) #does the calculations
  142.     labResult2.grid(row=5)
  143.     Label(bWindow, text = " ").grid(row=6)
  144.  
  145.  
  146.     labResult3 = Label(bWindow, text = ("Money made S3: $" + str((session3[0]*15)+(session3[1]*8)))) #does the calculations
  147.     labResult3.grid(row=7)
  148.     Label(bWindow, text = " ").grid(row=8)
  149.  
  150.  
  151.     labResult4 = Label(bWindow, text = ("Money made S4: $" + str((session4[0]*15)+(session4[1]*8)))) #does the calculations
  152.     labResult4.grid(row=9)
  153.     Label(bWindow, text = " ").grid(row=10)
  154.  
  155.     labTotal = Label(bWindow, text =("Total Money made: $" + str((session1[0]*15)+(session1[1]*8+(session2[0]*15)+(session2[1]*8)+session3[0]*15)+(session3[1]*8+session4[0]*15)+(session4[1]*8))))
  156.     labTotal.grid(row=11)
  157.     labDate = Label(bWindow, text =(time.strftime("%d/%m/%y")))
  158.     labDate.grid(row=12) #creates and positions text
  159.  
  160.     Button(bWindow, text="CLOSE", fg="red", command=bWindow.destroy).grid(row=13)
  161.    
  162. def exitcomm(): #defines exit command
  163.     cWindow = Toplevel(root) #new window
  164.     labExit = Label(cWindow, text = "are you sure you want to exit?")
  165.     labExit.pack() #creates and positions text
  166.     btnYes = Button(cWindow, text ="YES", command =root.destroy, fg="red")
  167.     btnYes.pack()
  168.     btnNo= Button(cWindow, text = "CANCEL", command =cWindow.destroy)
  169.     btnNo.pack() #creates and positions button
  170.  
  171. root = Tk() #creates the main window
  172. root.title("Cinema Management Menu") #title of mainwindow
  173. root.maxsize(width=600, height=350)
  174. root.minsize(width=600, height=350) #specifies maximum and minimum size in pixels
  175.  
  176. welcome = Label(root, text = "Cinema Management Software Menu", font=("Cambria", 28)) #text with text size
  177. welcome.pack()
  178. Label(root, text = "By Gryff and Ben",).place(x = 300, y= 325, anchor= CENTER)
  179. b1 = Button(root, text ="Attendance Details",padx=50, pady=25, command=attendance)
  180. b1.place(x =175 , y = 100, anchor = CENTER)
  181. b2 = Button(root, text ="Revenue Stastics", command=revenue, padx=50, pady=25, state=DISABLED)
  182. b2.place(x =425, y = 100, anchor = CENTER)
  183. b3 = Button(root, text ="EXIT", fg = "red", command =exitcomm, padx=50, pady=25)
  184. b3.place(x = 300, y =200, anchor = CENTER) #places and creates buttons and text
  185. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement