Reputation:
I'm trying to display a different cursor when the mouse arrives on the menu elements, I thought that to do that you had to add the cursor='something'
option at the options when you create the menu
try:
import tkinter as tk
except ImportError:
import Tkinter as tk
class Settings:
def __init__(self, master):
# Elements of the menu
self.master=master
self.menu = tk.Menu(root, fg="red")
self.subMenu = tk.Menu(self.menu, cursor="hand1")
def openMenu(self):
# Configuration of the menu
self.menu.add_cascade(label="Options", menu=self.subMenu)
self.addOptionsSubMenu()
self.master.config(menu=self.menu)
def addOptionsSubMenu(self):
# Add elements at the sub menu
self.subMenu.add_command(label="Quit", command=self.quit)
self.subMenu.add_command(label="Do nothing", command=self.passa)
# Quit the function
def quit(self):
exit()
# Do nothing
def passa(self):
pass
root = tk.Tk()
app = Settings(root)
app.openMenu()
root.mainloop()
But as it is the cursor doesn't change, how do I do this?
Upvotes: 1
Views: 900
Reputation: 4407
The docs for tkinter Menu
state that the cursor option denotes "The cursor that appears when the mouse is over the choices, but only when the menu has been torn off
". So, I don't think you can actually do what you want. Only when your sub menu has been detached (torn off), you can see your cursor changing. Here is a Demo.
import tkinter as tk
class Settings:
def __init__(self, master):
# Elements of the menu
self.master=master
self.menu = tk.Menu(root, fg="red")
self.subMenu = tk.Menu(self.menu, cursor="plus")
def openMenu(self):
# Configuration of the menu
self.menu.add_cascade(label="Options", menu=self.subMenu)
self.addOptionsSubMenu()
self.master.config(menu=self.menu)
def addOptionsSubMenu(self):
# Add elements at the sub menu
self.subMenu.add_command(label="Quit", command=self.quit)
self.subMenu.add_command(label="Do nothing", command=self.passa)
# Quit the function
def quit(self):
exit()
# Do nothing
def passa(self):
pass
root = tk.Tk()
app = Settings(root)
app.openMenu()
root.mainloop()
Upvotes: 1