# How to remove a menu bar from a frame?

**URL:** <https://racket.discourse.group/t/how-to-remove-a-menu-bar-from-a-frame/2934>\
**Category:** Questions & Answers\
**Tags:** question, gui\
**Created:** [May 24, 2024, 12:00am UTC](https://racket.discourse.group/t/how-to-remove-a-menu-bar-from-a-frame/2934 "2024-05-24T00:00:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![cadence](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/cadence/32/998_2.png) [@cadence](https://racket.discourse.group/u/cadence)\
**Post date:** [May 24, 2024, 12:00am UTC](https://racket.discourse.group/t/how-to-remove-a-menu-bar-from-a-frame/2934/1 "2024-05-24T00:00:10Z")

</div>

For creating a menu bar, the documentation says:

> `new menu-bar%` - A [menu-bar%](https://docs.racket-lang.org/gui/menu-bar_.html) object is created for a particular [frame%](https://docs.racket-lang.org/gui/frame_.html) object. **A frame can have at most one menu bar;** an [exn:fail:contract](https://docs.racket-lang.org/reference/exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) 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:

```scheme
#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?

---

<div class="post-metadata">

**Author:** ![bakgatviooldoos](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/bakgatviooldoos/32/1381_2.png) [@bakgatviooldoos](https://racket.discourse.group/u/bakgatviooldoos)\
**Post date:** [May 25, 2024, 10:22am UTC](https://racket.discourse.group/t/how-to-remove-a-menu-bar-from-a-frame/2934/2 "2024-05-25T10:22:43Z")

</div>

Hi, @cadence.

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 hope that helps.

---

<div class="post-metadata">

**Author:** ![cadence](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/cadence/32/998_2.png) [@cadence](https://racket.discourse.group/u/cadence)\
**Post date:** [May 25, 2024, 11:36am UTC](https://racket.discourse.group/t/how-to-remove-a-menu-bar-from-a-frame/2934/3 "2024-05-25T11:36:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bakgatviooldoos](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/bakgatviooldoos/32/1381_2.png) [@bakgatviooldoos](https://racket.discourse.group/u/bakgatviooldoos)\
**Post date:** [May 25, 2024, 11:44am UTC](https://racket.discourse.group/t/how-to-remove-a-menu-bar-from-a-frame/2934/4 "2024-05-25T11:44:50Z")

</div>

I see. That is a pickle.

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.

![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/2/2063443012cc5b4841fafa6586402a4fe7d37d21.png)

![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/a/a618fbbe08a3c55efe2532e9e8ce79143e40fc6d.png)

---

<div class="post-metadata">

**Author:** ![cadence](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/cadence/32/998_2.png) [@cadence](https://racket.discourse.group/u/cadence)\
**Post date:** [May 25, 2024, 12:02pm UTC](https://racket.discourse.group/t/how-to-remove-a-menu-bar-from-a-frame/2934/5 "2024-05-25T12:02:37Z")

</div>

I meant that the menu bar will still reserve space in the window even if it is hidden/deleted. Try this larger example:

```scheme
#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.

---

<div class="post-metadata">

**Author:** ![bakgatviooldoos](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/bakgatviooldoos/32/1381_2.png) [@bakgatviooldoos](https://racket.discourse.group/u/bakgatviooldoos)\
**Post date:** [May 25, 2024, 12:08pm UTC](https://racket.discourse.group/t/how-to-remove-a-menu-bar-from-a-frame/2934/6 "2024-05-25T12:08:55Z")

</div>

Perhaps it is a platform-related issue, because I cannot recreate what you describe, although I understand what you mean.

![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/8/882be0927347543657d9796f2f82af6571119b6b.png)

![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/3/3fba35789fd320d5dbd3d708f68cb0e02cc91e2f.png)

![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/5/529575c9c4143e35536553f0913b7db0bf2df723.png)

Edit: I am running a Windows 10 Professional edition, to clarify the point.

---

<div class="post-metadata">

**Author:** ![cadence](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/cadence/32/998_2.png) [@cadence](https://racket.discourse.group/u/cadence)\
**Post date:** [May 25, 2024, 12:16pm UTC](https://racket.discourse.group/t/how-to-remove-a-menu-bar-from-a-frame/2934/7 "2024-05-25T12:16:53Z")

</div>

Oh, you're totally right! It does remove the menu entirely on Windows. On Linux I get the blank space left behind. Here's what it looks like for me:

 ![bitmap](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/0/00b7bd23cf3ee6da27ae910e8de2b502c8bbcbe5.png)

---

<div class="post-metadata">

**Author:** ![bakgatviooldoos](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/bakgatviooldoos/32/1381_2.png) [@bakgatviooldoos](https://racket.discourse.group/u/bakgatviooldoos)\
**Post date:** [May 25, 2024, 12:20pm UTC](https://racket.discourse.group/t/how-to-remove-a-menu-bar-from-a-frame/2934/8 "2024-05-25T12:20:29Z")

</div>

I wonder how you would troubleshoot the issue 🤔

Does it continue if you add a new item to the frame? Or perhaps, if you are using a tiling WM, move the window around?

Edit: I am alluding to whether this is a _platform_-related issue, or merely a "refresh" issue.

---

<div class="post-metadata">

**Author:** ![cadence](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/cadence/32/998_2.png) [@cadence](https://racket.discourse.group/u/cadence)\
**Post date:** [May 25, 2024, 12:36pm UTC](https://racket.discourse.group/t/how-to-remove-a-menu-bar-from-a-frame/2934/9 "2024-05-25T12:36:37Z")

</div>

> [@bakgatviooldoos](#):
>
> Does it continue if you add a new item to the frame?

Yes. I think it's a platform issue rather than a refresh issue.

---

<div class="post-metadata">

**Author:** ![mflatt](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/mflatt/32/6_2.png) [@mflatt](https://racket.discourse.group/u/mflatt)\
**Post date:** [May 25, 2024, 12:42pm UTC](https://racket.discourse.group/t/how-to-remove-a-menu-bar-from-a-frame/2934/10 "2024-05-25T12:42:02Z")

</div>

With Gtk, I think `racket/gui` reserves that menu-bar space here:

> <https://github.com/racket/gui/blob/master/gui-lib/mred/private/wx/gtk/frame.rkt#L281>

It's possible that some configuration could reset that space back to 0, although I'm not sure it would work right.
