Go to GoReading for breaking news, videos, and the latest top stories in world news, business, politics, health and pop culture.

How to Create a Cursor in Python

104 15
  • 1). Get an cursor file (usually ".ico" or ".cur" files) and save it. This image can be anything, from an image you create to a free cursor downloaded from the Internet, for instance from the Open Cursor Library. Python can use these images as cursors. Save the image in the directory where the script will reside.

  • 2). Create a window and button through the Python Tkinter library. In a text editor, enter the following code:

    #!/usr/bin/python

    from Tkinter import *

    root = Tk()

    b = Button(root, text="cursor")

    b.pack()

    root.mainloop()

    This example code creates a main window, containing a button with the text "cursor" on it. The button does not do anything at this point.

  • 3). Modify the button to change the cursor to the custom cursor when the mouse rolls over it. Currently, the "cursor" button does nothing. However, by adding an additional parameter, "cursor," a programmer can control what mouse cursor appears over the button. In this example, the "cursor" argument will specify a cursor named "custom.cur" located in the same directory as the current Python script.

    b = Button(root, text="cursor", cursor="@custom.cur")

Source...

Leave A Reply

Your email address will not be published.