## These cannot be run by examples() but should be OK when pasted
## into an interactive R session with the tcltk package loaded
## Run these commands one at a time and look at menus...
## Under RGui and Windows only! ##
# Create menus in Rgui, using a specification file
MenuReadPackage("svWidgets")
MenuNames()
(MenuItems("$ConsoleMain/Testit"))
# Create menus manually in Rgui
MenuAdd("$ConsoleMain/Testit2")
MenuAddItem("$ConsoleMain/Testit2", "Trial", "ls()")
MenuNames()
(MenuItems("$ConsoleMain/Testit2"))
MenuStateItem("$ConsoleMain/Testit2", "Trial", FALSE)
MenuStateItem("$ConsoleMain/Testit2", "Trial", TRUE)
# Buggy? -> MenuChangeItem("$ConsoleMain/Testit2", "Trial", "search()")
(MenuItems("$ConsoleMain/Testit2"))
## Under any system supporting Tcl/Tk ##
# Create and manipulate Tk menus
WinAdd("tt", title = "A Tk window with menus", pos ="-40+20")
MenuAdd("$Tk.tt/Misc")
MenuNames()
(MenuItems("$Tk.tt/Misc")) # Still nothing in it
MenuAddItem("$Tk.tt/Misc", "List &variables", "print(ls(envir = .GlobalEnv))")
MenuAddItem("$Tk.tt/Misc", "Say &yo!", "cat('yo!\n')")
MenuDelItem("$Tk.tt/Misc", "Say &yo!")
MenuAddItem("$Tk.tt/Misc", "-")
MenuAddItem("$Tk.tt/Misc", "&Say yo! twice", "cat('yo! yo!\n')")
(MenuItems("$Tk.tt/Misc"))
ImgReadPackage("svWidgets") # Make sure images are loaded
MenuAdd("$Tk.tt/Misc/Sub&Menu")
MenuAddItem("$Tk.tt/Misc/Sub&Menu", "T&rial", "cat('Trial trigerred!\n')")
MenuAddItem("$Tk.tt/Misc", "Tria&l2", "cat('Trial with image and accel!\n')",
image = "$Tk.butOpen", accel = "Ctrl+T")
MenuNames()
(MenuItems("$Tk.tt/Misc"))
MenuStateItem("$Tk.tt/Misc", "Tria&l2", FALSE)
MenuStateItem("$Tk.tt/Misc", "Tria&l2", TRUE)
MenuStateItem("$Tk.tt/Misc", "Sub&Menu", FALSE)
MenuStateItem("$Tk.tt/Misc", "Sub&Menu", TRUE)
MenuChangeItem("$Tk.tt/Misc", "Tria&l2", options = "underline = 1")
# This is the way to change binding
tkbind(WinGet("tt"), "<Control-r>", function() MenuInvoke("$Tk.tt/Misc", "Tria&l2"))
MenuChangeItem("$Tk.tt/Misc", "Tria&l2", action = 'cat("new action for Tria&l2!\n")')
MenuInvoke("$Tk.tt/Misc", "Tria&l2")
(MenuItems("$Tk.tt/Misc"))
MenuDelItem("$Tk.tt/Misc", "Tria&l2")
MenuDel("$Tk.tt/Misc")
MenuNames()
# The following command generates an error!
(MenuItems("$Tk.tt/Misc"))
WinDel("tt")Run the code above in your browser using DataLab