Search code examples
tkinter

Using OS X standard cursors in Tkinter


I found a bunch of OS X cursors in: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HiServices.framework/Versions/A/Resources/cursors

Each cursor is a directory with two files: cursor.pdf and info.plist

It includes useful things such openhand, zoomin, zoomout, and many others. Is there a way to access these in Tkinter? Or, alternatively, is there a way to use an image as a cursor in Tkinter? It only needs to work in OS X.


Solution

  • You can use the cursor= argument when defining a widget, and it will display the proper cursor depending on your operating system. For example, the following Python 3 code creates a simple window that uses the cross cursor with a button that will change the cursor to plus on hover:

    import tkinter as tk
    
    root = tk.Tk()
    
    root.config(cursor='cross')
    root.geometry('600x400')
    
    testButton = tk.Button(root, text='Hover over here!', cursor='plus')
    testButton.pack()
    
    root.mainloop()
    

    You can find a list of built-in cursors for all platforms here, but you can scroll down to find the list of Mac specific cursors.

    As for custom cursors, you could create a .cur file with an image processor and then apply it to a widget with cursor='@filename.cur', just be sure that the .cur file is in the same directory as your script.