here2share

# Tk_squiggly.py

May 13th, 2021
535
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Tk_squiggly.py
  2.  
  3. SCREENSAVER_BACKGROUND_COLOR="black"
  4. TRANSPARENCY_LEVEL = 0.75
  5. COLOR_CHOICE = ['blue',"red","yellow","white","skyblue","green"]
  6. PIPE_WIDTH = 10
  7. WAITING_TIME_LAP = 0.09
  8. RESTARTING_POINT = 100
  9. LOOK_LIKE_THREAD = True
  10.  
  11. import tkinter as Tkinter
  12. import random
  13. import time
  14.  
  15. class Pipes(Tkinter.Canvas):
  16.     def __init__(self, *args, **kwargs):
  17.         Tkinter.Canvas.__init__(self, *args, **kwargs)
  18.         # Starting Coordinates
  19.         self.coordinates=[0,0,0,0]
  20.         # Create Line Function
  21.         self.create_pipe()
  22.  
  23.     def create_pipe(self):
  24.         self.p = self.create_line(0,0,0,0, fill=random.choice(COLOR_CHOICE),smooth=LOOK_LIKE_THREAD ,width=PIPE_WIDTH)
  25.         return
  26.  
  27.     def update_screen(self):
  28.         self.coordinates.append(random.randint(0,self.winfo_screenwidth()))
  29.         self.coordinates.append(random.randint(0,self.winfo_screenheight()))
  30.         self.coords(self.p, *self.coordinates)
  31.         time.sleep(WAITING_TIME_LAP)
  32.         if len(self.coordinates)>RESTARTING_POINT:
  33.             self.coordinates=[0,0,0,0]
  34.             color = random.choice(COLOR_CHOICE)
  35.             self.itemconfigure(self.p, fill=color)
  36.         return
  37.  
  38. # Main Functions
  39. def main():
  40.     root=Tkinter.Tk(className="# Tk_squiggly.py")
  41.     screen = Pipes(root, bg=SCREENSAVER_BACKGROUND_COLOR)
  42.     screen.pack(expand="yes",fill="both")
  43.     # Tkinter Window Configurations
  44.     root.wait_visibility(screen)
  45.     root.wm_attributes('-alpha',TRANSPARENCY_LEVEL)
  46.     root.wm_attributes("-topmost", True)
  47.     root.attributes('-fullscreen', True)
  48.    
  49.     go=[1]
  50.  
  51.     def out(event):
  52.         go[0]=0
  53.  
  54.     root.bind_all('<Any-KeyPress>', out)
  55.  
  56.     while go[0]:
  57.         root.update()
  58.         root.update_idletasks()
  59.         screen.update_screen()
  60.     root.destroy()
  61.  
  62. if __name__=='__main__':
  63.     main()
RAW Paste Data