Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/python
- from itertools import count
- from Tkinter import * # imports Tkinter lbrary
- import sys
- import time
- class Application(Frame): # Creates a class so other widgets can be created later
- 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
- Frame.__init__(self, master) # Subclasses Frame
- self.grid() # Frame.grid() a method of displaying widgets like grid but better
- self.createWidgets() # runs the function createWidgets(self) as a parent of Application
- self.label = Label(self)
- self.label.grid()
- 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
- self.ciphertext=""
- self.key=1
- self.message=""
- self.y=0
- self.x=0
- self.l=""
- self.sleep=1
- def createWidgets(self): # It be a function!
- self.quitButton = Button ( self, text="Quit", command=self.quit ) # Creats a button saying quit that quits the app
- self.quitButton.grid() # grids it
- def cipherGUI(self):
- global w2
- global w3
- l1= Label ( self, text="Enter a string to shift: ")
- l1.grid()
- w2 = Entry(self)
- w2.grid()
- message = w2.get()
- l1= Label ( self, text="Enter Shift Ammount: ")
- l1.grid()
- w3 = Entry(self)
- w3.grid()
- key = w3.get()
- button = Button ( self, text="Shift It!", command=self.cipherText)
- button.grid()
- def scroll(self):
- a=self.alph[self.x]
- self.label.config(text=self.ciphertext+a)
- if a!=self.l:
- self.x+=1
- self.label.after(75, self.scroll)
- def update_func(self):
- last_letter = 0
- self.l=""
- if self.message[self.y] in self.alph:
- self.l=self.alph[(self.alph.index(self.message[self.y])+self.key)%26]
- else:
- self.l=self.message[self.y]
- self.x=0
- self.y+=1
- if self.y < len(self.message):
- self.ciphertext+=self.l
- self.label.config(text=self.ciphertext)
- if self.y < len(self.message):
- self.scroll()
- self.label.after(100, self.update_func)
- def cipherText(self):
- global ciphertext
- self.key = w3.get()
- self.key = int(self.key)
- self.message = w2.get()
- self.message = str(self.message)
- self.key=self.key%26
- self.ciphertext = ""
- self.label.config(text="")
- self.y=0
- self.update_func()
- app = Application() # Self explanatory
- app.master.title("Testing") # Frame.master.title is set to sample application
- app.cipherGUI()
- app.mainloop() # runs everything
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement