Guest User

regis.py

a guest
Apr 16th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.35 KB | None | 0 0
  1. from Tkinter import *
  2. import tkMessageBox
  3. from PIL import Image, ImageTk
  4.  
  5.  
  6. class Registration(Label):
  7.     def init(self, root, filename):
  8.         im = Image.open(filename)
  9.         seq =  []
  10.         try:
  11.             while 1:
  12.                 seq.append(im.copy())
  13.                 im.seek(len(seq)) # skip to next frame
  14.         except EOFError:
  15.             pass # we're done
  16.  
  17.         try:
  18.             self.delay = im.info['duration']
  19.         except KeyError:
  20.             self.delay = 100
  21.  
  22.         first = seq[0].convert('RGBA')
  23.         self.frames = [ImageTk.PhotoImage(first)]
  24.         Label.init(self, root, image=self.frames[0])
  25.  
  26.         temp = seq[0]
  27.  
  28.         for image in seq[1:]:
  29.             temp.paste(image)
  30.             frame = temp.convert('RGBA')
  31.             self.frames.append(ImageTk.PhotoImage(frame))
  32.  
  33.         self.idx = 0
  34.  
  35.         self.cancel = self.after(self.delay, self.play)
  36.  
  37.         self.root = root
  38.  
  39.         self.root.title('Registration')
  40.         self.root.resizable(0,0)
  41.         self.w = 500
  42.         self.h = 500
  43.         self.ws = self.root.winfo_screenwidth()
  44.         self.hs = self.root.winfo_screenheight()
  45.         self.x = (self.ws/2) - (self.w/2)
  46.         self.y = (self.hs/2) - (self.h/2)
  47.         self.root.geometry('%dx%d+%d+%d' % (self.w, self.h, self.x, self.y))
  48.         self.root.configure(background = 'grey')
  49.         self.image = Image.open('image1.jpg')
  50.         self.photo_image = ImageTk.PhotoImage(self.image)
  51.         self.label = Label(root, image = self.photoimage, bd = 0)
  52.         self.label.pack(side = BOTTOM)
  53.  
  54.         self.name = Label(root, text = 'NAME', font = ('Times New Roman',
  55.             '8', 'bold'))
  56.         self.name.place(width = 50, height = 20, x = 40, y = 280)
  57.         self.namevariable = StringVar()
  58.         vcmd = (root.register(self.validname), '%d', '%i', '%P', '%s', '%S',
  59.             '%v', '%V', '%W')
  60.         self.user = Entry(root, width = 30, textvariable =
  61.             self.namevariable, validate = "key", validatecommand = vcmd)
  62.         self.user.place(x = 100, y = 280)
  63.  
  64.         self.age = Label(root, text = 'AGE', font = ('Times New Roman', '8',
  65.             'bold'))
  66.         self.age.place(width = 50, height = 20, x = 40, y = 320)
  67.         vcmd = (root.register(self.validage), '%d', '%i', '%P', '%s', '%S',
  68.             '%v', '%V', '%W')
  69.         self.userage = Spinbox(root, from= 1, to = 100, justify = CENTER,
  70.             width = 5, validate = "key", validatecommand = vcmd, wrap = True)
  71.         self.userage.place(x = 100, y = 320)
  72.  
  73.         self.sexvar = IntVar()
  74.         self.sex = Label(root, text = 'SEX', font = ('Times New Roman', '8',
  75.             'bold'))
  76.         self.sex.place(width = 50, height = 25, x = 40, y = 360)
  77.         self.male = Radiobutton(root, text = 'Male',  variable =
  78.             self.sexvar, value = 1)
  79.         self.male.place(x = 100, y = 360)
  80.         self.female = Radiobutton(root, text = 'Female', variable =
  81.             self.sexvar,  value = 2)
  82.         self.female.place(x = 165, y = 360)
  83.  
  84.         self.dob = Label(root, text = 'D.O.B', font = ('Times New Roman',
  85.             '8', 'bold'))
  86.         self.dob.place(width = 50, height = 20, x = 40, y = 400)
  87.         vcmd = (root.register(self.validdays), '%d', '%i', '%P', '%s', '%S',
  88.             '%v', '%V', '%W')
  89.         self.days = Spinbox(root, from = 1, to = 31, justify = CENTER,
  90.             width = 5, wrap = True, validate = 'key', validatecommand = vcmd)
  91.         self.days.place(x = 100, y = 400)
  92.         self.months = Spinbox(root, values = ('Jan', 'Feb', 'Mar', 'Apr',
  93.             'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), justify = CENTER,
  94.             width = 5,wrap = True, state = 'readonly')
  95.         self.months.place(x = 150, y = 400)
  96.         var = StringVar()
  97.         var.set('2017')
  98.         self.year = Spinbox(root, from = 1970, to = 2050, justify = CENTER,
  99.             width = 5, wrap = True, textvariable = var, state = 'readonly')
  100.         self.year.place(x = 200, y = 400)
  101.         self.username = Label(root, text = 'USERNAME', font = ('Times New
  102.            Roman', '8', 'bold'))
  103.         self.username.place(width = 80, height = 20, x = 40, y = 440)
  104.         self.uservariable = StringVar()
  105.         vcmd = (root.register(self.validusername), '%d', '%i', '%P', '%s',
  106.             '%S', '%v', '%V', '%W')
  107.         self.entry = Entry(root, width = 30, validate = "key",
  108.             validatecommand = vcmd, textvariable = self.uservariable)
  109.         self.entry.place(x = 130, y = 440)
  110.         self.password = Label(root, text = 'PASSWORD', font = ('Times New
  111.            Roman', '8', 'bold'))
  112.         self.password.place(width = 80, height = 20, x = 40, y = 470)
  113.         self.passentry = Entry(root, width = 30, show = '*')
  114.         self.passentry.place(x = 130, y = 470)
  115.         self.register = Button(root, font = ('NeuropolXRg-Regular', '8'),
  116.             text = 'REGISTER', activebackground = 'grey', activeforeground = 'white',
  117.             command = self.registration)
  118.         self.register.pack()
  119.         self.register.place(height = 50, width = 100, x = 390, y = 440)
  120.  
  121.     def validname(self, d, i, P, s, S, v, V, W):
  122.         if S in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ':
  123.             return True
  124.         else:
  125.             self.bell()
  126.             return False
  127.  
  128.     def validage(self, d, i, P, s, S, v, V, W):
  129.         if P in str(range(1, 101)):
  130.             return True
  131.         else:
  132.             self.bell()
  133.             return False
  134.  
  135.     def validdays(self, d, i, P, s, S, v, V, W):
  136.         if P in str(range(1, 32)):
  137.             return True
  138.         else:
  139.             self.bell()
  140.             return False
  141.  
  142.     def validusername(self, d, i, P, s, S, v, V, W):
  143.         if S in 'abcdefghijklmnopqrstuvwxyz1234567890':
  144.             return True
  145.         else:
  146.             return False
  147.  
  148.     def play(self):
  149.         self.config(image=self.frames[self.idx])
  150.         self.idx += 1
  151.         if self.idx == len(self.frames):
  152.             self.idx = 0
  153.         self.cancel = self.after(self.delay, self.play)
  154.  
  155.     def registration(self):
  156.         if not ' ' in self.namevariable.get():
  157.             tkMessageBox.showerror('ERROR', 'Full name is required')
  158.         else:
  159.             root.destroy()
  160.             print 'hello'
  161.  
  162.             raw_input()
  163.  
  164.  
  165.  
  166.  
  167. root = Tk()
  168. anim = Registration(root, 'tuhin.gif')
  169. anim.pack()
  170.  
  171. root.mainloop()
Add Comment
Please, Sign In to add comment