Is it possible to create a custom mouse cursor with Python Tkinter? (Using matplotlib with the TkAgg backend)

This is probably just a general Python Tkinter question, not necessarily matplotlib.

So, I'm in the development of a fairly large set of charting functions on top of matplotlib using the Matplotlib backend "TkAgg" (Agg rendering on Tk canvas using TkInter). I use some of the default scaling functions provided by matplotlib out of the box ... in particular, the "Enlarge window" button on the matplotlib toolbar by default. I create my own toolbar by subclassing the existing matplotlib.backends.backend_tkagg.NavigationToolbar2TkAgg class.

To a large extent, the problem is that I hate the default icon, which uses "Zoom to box" (Tcinter "tcross"). I figured out how to use another Tkinter built-in cursor (for example, this changes the cursor to a plus instead of tcross):

import matplotlib
matplotlib.use('TkAgg')

import matplotlib.backend_bases
import matplotlib.backends.backend_tk_agg

matplotlib.backends.backend_tkagg.cursord[matplotlib.backend_bases.cursors.SELECT_REGION] = "plus"

In general, I know that to change the current mouse cursor to one of the built-in Tkinter from the toolbar class, I can simply call:

self.window.configure(cursor="cursor_name")

, . .ppm , , , , . Python Tkinter? !

. Mac OS X 10.5+, RedHat Enterprise Linux 5 , , Solaris 10, .

+3
1

- unix X11 XBM:

import Tkinter
t = Tkinter.Tk()
t.configure(cursor=('@/usr/include/X11/bitmaps/star', '/usr/include/X11/bitmaps/starMask', 'black', 'white'))
t.mainloop()

Mac, "Tk_GetCursorFromData":

Tk Macintosh X-                Mac               ibeam, , , . , Tk                Macintosh crsr ()               CURS ( ) .
                              .                               .

+3

Source: https://habr.com/ru/post/1725224/


All Articles