Advertisement
Guest User

Andrew

a guest
May 8th, 2009
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.96 KB | None | 0 0
  1. #!/usr/local/bin/python  
  2. from itertools import count    
  3. from Tkinter import *       # imports Tkinter lbrary
  4. import sys
  5. import time
  6. class Application(Frame):              # Creates a class so other widgets can be created later
  7.     def __init__(self, master=None):  # Runs on any thing passed to it, if None is passed a new TK Interpter will be started as well as a new window
  8.         Frame.__init__(self, master)   # Subclasses Frame
  9.         self.grid()                    # Frame.grid() a method of displaying widgets like grid but better
  10.         self.createWidgets()           # runs the function createWidgets(self) as a parent of Application
  11.         self.label = Label(self)
  12.         self.label.grid()
  13.         self.alph = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z".split(",")  # Creates a string a-z
  14.         self.ciphertext=""
  15.         self.key=1
  16.         self.message=""
  17.         self.y=0
  18.         self.x=0
  19.         self.l=""
  20.         self.sleep=1
  21.     def createWidgets(self):         # It be a function!
  22.         self.quitButton = Button ( self, text="Quit", command=self.quit ) # Creats a button saying quit that quits the app      
  23.         self.quitButton.grid()         # grids it  
  24.  
  25.  
  26.     def cipherGUI(self):
  27.         global w2
  28.         global w3      
  29.         l1= Label ( self, text="Enter a string to shift: ")
  30.         l1.grid()
  31.         w2 = Entry(self)
  32.         w2.grid()
  33.         message = w2.get()
  34.         l1= Label ( self, text="Enter Shift Ammount: ")
  35.         l1.grid()
  36.         w3 = Entry(self)
  37.         w3.grid()
  38.         key = w3.get()
  39.         button = Button ( self, text="Shift It!", command=self.cipherText)
  40.         button.grid()
  41.     def scroll(self):    
  42.  
  43.         a=self.alph[self.x]
  44.         self.label.config(text=self.ciphertext+a)
  45.         if a!=self.l:
  46.             self.x+=1
  47.             self.label.after(75, self.scroll)
  48.              
  49.     def update_func(self):
  50.         last_letter = 0
  51.         self.l=""
  52.        
  53.         if self.message[self.y] in self.alph:
  54.             self.l=self.alph[(self.alph.index(self.message[self.y])+self.key)%26]
  55.  
  56.         else:
  57.             self.l=self.message[self.y]
  58.  
  59.         self.x=0
  60.         self.y+=1
  61.         if self.y < len(self.message):
  62.             self.ciphertext+=self.l
  63.             self.label.config(text=self.ciphertext)
  64.            
  65.         if self.y < len(self.message):
  66.             self.scroll()
  67.             self.label.after(100, self.update_func)
  68.  
  69.  
  70.  
  71.     def cipherText(self):
  72.         global ciphertext
  73.         self.key = w3.get()
  74.         self.key = int(self.key)
  75.         self.message = w2.get()
  76.         self.message = str(self.message)
  77.         self.key=self.key%26
  78.         self.ciphertext = ""
  79.         self.label.config(text="")
  80.         self.y=0
  81.         self.update_func()
  82.        
  83.  
  84.    
  85. app = Application()                    # Self explanatory
  86. app.master.title("Testing")  # Frame.master.title is set to sample application
  87. app.cipherGUI()
  88.  
  89.  
  90. app.mainloop()  # runs everything
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement