Showing posts with label cursors. Show all posts
Showing posts with label cursors. Show all posts

Thursday, 23 April 2015

Cursors in Python Tkinter

Now it's time to use one of the stuff that support Python TKinter: mouse cursor.





The simple way to show how this works is shown with the next code (used in a previous post, with a little modification):

import Tkinter
root = Tkinter.Tk()
button = Tkinter.Button(root, text = "Forgotten Sign", cursor="rtl_logo").pack()
root.mainloop()

img_cursor_test_tk_0101

The next code is a modification of a previous posted code that uses the class mechanism:

from Tkinter import *

def frame(root, side):
    # wf : Window Frame
    wf = Frame(root)
    wf.pack(side=side, expand=YES, fill=BOTH)
    return wf

def button(root, side, text, command=None, cursor=None):
    btn = Button(root, text=text, command=command, cursor=cursor)
    btn.pack(side=side, expand=YES, fill=BOTH)
    return btn

class Sample(Frame):
    def __init__(self):
        Frame.__init__(self)
        self.pack(expand=YES, fill=BOTH)
        self.master.title("Simpl3")
        self.master.iconname("Simpl3")

        opsF = frame(self, TOP)
        btn0 = button(opsF, LEFT, "About time!", cursor="pirate")
        btn1 = button(opsF, LEFT, "Pattern", cursor="rtl_logo")
        btn2 = button(opsF, LEFT, "Preloading...", cursor="watch")

if __name__ == "__main__":
    Sample().mainloop()

img_cursor_test_tk_0202

Well, there has been some troubles at taking shots from the frickin' cursor, this post was with the lonely initial picture, but now that's been fixed :P

The next list mention a few of them:
-arrow
-circle
-clock
-cross
-dotbox
-exchange
-fleur
-hand1
-hand2
-heart
-man
-pirate
-plus
-sailboat
-star
-target
-trek
-watch
-xterm

In the next links you can find a list of cursors:
§ http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/cursors.html

§ http://www.tcl.tk/man/tcl8.4/TkCmd/cursors.htm