new menu-bar% - A menu-bar% object is created for a particular frame% object. A frame can have at most one menu bar; an exn:fail:contract exception is raised when a new menu bar is created for a frame that already has a menu bar.
I can create a menu bar with this code:
#lang racket/gui
(define frame (new frame% [label "Racket Frame"] [width 200] [height 200]))
(define menu-bar (new menu-bar% [parent frame]))
(define menu (new menu% [label "File"] [parent menu-bar]))
(send frame show #t)
After it has been created, how can I remove the menu bar from the frame?
I had a quick look at the source for the menu-bar% and frame%. I am just spit-balling here, so take with a grain of salt, but I think the intended "workflow" if you will, is to have a single menu bar, which is either visible or not, which has items which can delete themselves. So, the menu bar itself stays constant, but its content varies.
I see. So I can (send menu delete) and (send menu restore) to hide/show. That works to clear the items, but the blank space remains there at the top of the window. I guess that's good enough.
My workaround was to delete and re-create the entire window. This works well enough for me, but one notable downside is if it's been moved around the screen by the user, it'll reappear in the middle.
Maybe you can "hide" the menu bar with (send menu-bar enable #false), which will disable it. But I don't know if that has the intended effect from just one test.
I meant that the menu bar will still reserve space in the window even if it is hidden/deleted. Try this larger example:
#lang racket/gui
(define frame (new frame% [label "Racket Frame"] [width 200] [height 200]))
(define check (new check-box%
[parent frame]
[label "Check Box"]
[value #t]))
(send frame show #t)
(define menu-bar (box #f))
(define menu (box #f))
(define (create-menu)
(set-box! menu-bar (new menu-bar% [parent frame]))
(set-box! menu (new menu% [label "File"] [parent (unbox menu-bar)])))
(define (disable-delete-menu)
(send (unbox menu-bar) enable #f)
(send (unbox menu) delete))
At first the menu bar doesn't exist, so the checkbox is right next to the top of the window.
Then, after running (create-menu) in the REPL, the menu bar is added to the top of the window and pushes the checkbox down a bit.
Finally, after running (disable-delete-menu) in the REPL, the menu bar disappears but it isn't truly gone. It leaves behind a blank space at the top of the window, stopping the checkbox from going back to the top of the window.