how to create beautiful moving thread/pipe like screen saver using python and tkinter - tutorial - one

Namaste friends,






                                        Today, I am going to show you how to create a beautiful moving pipe/thread like screen saver written in python?


and one of the unique features of this script is, we will create this screen saver with the help of python standard GUI module called Tkinter.

yes! yes!  Tkinter.


Python Tkinter Module is a Standard GUI library come with python. so, you don't need to install this module separately. and that's why this screen saver is cross platform supported.



With the help of basic knowledge of python and Tkinter. we can do many things. like in this script, i used normal python tkinter canvas widget to create moving pipes and random module for choicing random coordinates of pipes.

 Simple!

here are my python codes.

friends, for better understanding I am using lots of comments.

only for you. So,

Keep Reading & Pay Attention

1. Python Tkinter Thread/Pipe ScreenSaver.py 



  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/python

# ---------------- READ ME ---------------------------------------------
# This Script is Created Only For Practise And Educational Purpose Only
# This is an Example Of Tkinter Canvas Graphics
# This Script Is Created For http://bitforestinfo.blogspot.in
# This Script is Written By
#
#
##################################################
######## Please Don't Remove Author Name #########
############### Thanks ###########################
##################################################
#
#
__author__='''

######################################################
                By S.S.B Group                          
######################################################

    Suraj Singh
    Admin
    S.S.B Group
    surajsinghbisht054@gmail.com
    http://bitforestinfo.blogspot.in/

    Note: We Feel Proud To Be Indian
######################################################
'''
print __author__
# ============ CONFIGURATIONS =====================
SCREENSAVER_BACKGROUND_COLOR="black"
TRANSPARENCY_LEVEL = 0.75
COLOR_CHOICE = ['blue',"red","yellow","white","skyblue","green"]
SCREEN_SAVER_CLOSING_EVENTS = ['<Any-KeyPress>', '<Any-Button>', '<Motion>']
PIPE_WIDTH = 10
WAITING_TIME_LAP = 0.09
RESTARTING_POINT = 100
LOOK_LIKE_THREAD = True
# =================================================

# *************** Importing Module ****************
try:
    import Tkinter
    import random
    import time
except:
    import tkinter as Tkinter
    import random
    import time


# Create Canvas Class
class Pipes(Tkinter.Canvas):
    def __init__(self, *args, **kwargs):
        Tkinter.Canvas.__init__(self, *args, **kwargs)
        # Starting Coordinates
        self.coordinates=[0,0,0,0]
        # Create Line Function
        self.create_pipe()

    # Create A Line
    def create_pipe(self):
        self.p = self.create_line(0,0,0,0, fill=random.choice(COLOR_CHOICE),smooth=LOOK_LIKE_THREAD ,width=PIPE_WIDTH)
        return

    # update Canvas Configurations
    def update_screen(self):
        self.coordinates.append(random.randint(0,self.winfo_screenwidth()))
        self.coordinates.append(random.randint(0,self.winfo_screenheight()))
        self.coords(self.p, *self.coordinates)
        time.sleep(WAITING_TIME_LAP)
        if len(self.coordinates)>RESTARTING_POINT:
            self.coordinates=[0,0,0,0]
            color = random.choice(COLOR_CHOICE)
            self.itemconfigure(self.p, fill=color)
        return

# Main Functions
def main():
    root=Tkinter.Tk(className="Pipes screenSaver By Bitforestinfo")
    screen = Pipes(root, bg=SCREENSAVER_BACKGROUND_COLOR)
    screen.pack(expand="yes",fill="both")
    # Tkinter Window Configurations
    root.wait_visibility(screen)
    root.wm_attributes('-alpha',TRANSPARENCY_LEVEL)
    root.wm_attributes("-topmost", True)
    root.overrideredirect(1)
    root.attributes('-fullscreen', True)
    # Window Exit Functions
    def out(event):
        root.destroy()
        return
    # Event Bindings
    for seq in SCREEN_SAVER_CLOSING_EVENTS:
        root.bind_all(seq, out)

    # Update Loop
    while True:
        root.update()
        root.update_idletasks()
        screen.update_screen()
    return


#============ Trigger ========================  
if __name__=='__main__':
    main()

or if you want to download this script.

then,

check here my GitHub Repository here.

after running this codes.


screen saver look like this




This Tutorial End Here! :)

if you like my blog. then,
don't forget to subscribe,
comment and share.

 Thanks for reading 
have a nice day

Share this

Related Posts

Previous
Next Post »