hide mouse pointer in Tkinter

Matthew Dixon Cowles matt at mondoinfo.com
Wed Jul 17 17:02:41 EDT 2002


On Wed, 17 Jul 2002 20:41:40 GMT, Douglas Zongker
<dougz at cs.washington.edu> wrote:

> How can I hide the mouse pointer in a Tkinter window?  The Tk docs
> say that cursor "no" is an empty image, but on my system it's a
> slash-and-circle icon.  I tried using Tk_GetCursorFromData to create
> an empty cursor, but this function always fails on Win32.

Dear Douglas,
The only way I've found is to write the xbm data for a "blank" cursor
to a file and set the widget to use that file as a cursor. I'll append
a small example.

Regards,
Matt


#!/usr/local/bin/python

from Tkinter import *

import os

kNullCursorData="""
  #define t_cur_width 1
  #define t_cur_height 1
  #define t_cur_x_hot 0
  #define t_cur_y_hot 0
  static unsigned char t_cur_bits[] = { 0x00};
  """

class mainWin:

  def __init__(self,root):
    self.root=root
    # Should clean this up on quit
    os.umask(0177) # octal
    f=open("testcursor","w")
    f.write(kNullCursorData)
    f.close()
      
    self.createWidgets()
    return None

  def createWidgets(self):
    self.t=Text(self.root,bg="white",cursor="@testcursor white")
    self.t.pack()
    return None

def main():
  root=Tk()
  mainWin(root)
  root.mainloop()
  return None

if __name__=="__main__":
  main()




More information about the Python-list mailing list