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

4 comments:

  1. Great examples! Good job

    Also, I didn't know the page: http://www.tcl.tk/
    This page is going to help me a lot
    Thank you

    ReplyDelete
  2. Great and I have a neat offer: Who Repairs House Windows remodel outside of house

    ReplyDelete