如何从电子应用程序中删除此菜单栏:

它还说“Hello World”(这是因为我下载了电子预构建,一旦我打包应用程序就会消失吗?)我没有编码这些到html,所以我不知道如何得到它!-


当前回答

setMenu(空);是不是autohidemenu的最佳答案会在应用程序启动时显示


    function createWindow(){
        const win = new BrowserWindow({
            width: 1500,
            height: 800,
            webPreferences:{
                nodeIntergration: true
            }
        });
        win.setMenu(null);
    win.loadFile("index.html");
    }
    app.whenReady().then(createWindow);

其他回答

你可以在你的窗口上使用w.setMenu(null)或set frame: false(这也会删除关闭、最小化和最大化选项的按钮)。参见setMenu()或BrowserWindow()。还要检查这个线程


Electron现在有win.removeMenu()(在v5.0.0中添加),以删除应用程序菜单,而不是使用win.setMenu(null)。


7.1电子。x似乎有一个错误,win.removeMenu()不工作。唯一的解决方法是使用menu . setapplicationmenu (null),然而,这将禁用所有菜单快捷方式,如F11切换全屏等。


在新版本的Electron中,您可以在创建browserWindow时设置autoHideMenuBar: true,按Alt将再次显示菜单栏。

const mainWindow = new BrowserWindow({
  autoHideMenuBar: true,
})
@"electron": "^7.1.1" : 

mainWindow = new browserWindow({ height: 500, width: 800});
//mainWindow.setAutoHideMenuBar(true);
mainWindow.autoHideMenuBar = true;

在浏览器中没有菜单的情况下正常工作。

setMenu(空);是不是autohidemenu的最佳答案会在应用程序启动时显示


    function createWindow(){
        const win = new BrowserWindow({
            width: 1500,
            height: 800,
            webPreferences:{
                nodeIntergration: true
            }
        });
        win.setMenu(null);
    win.loadFile("index.html");
    }
    app.whenReady().then(createWindow);

在创建browserWindow时设置autoHideMenuBar为true

mainWindow = new BrowserWindow({
    autoHideMenuBar: true,
    width: 1200,
    height: 800
})

这些解决方案有缺陷。 当使用以下溶液时,窗口在关闭时有延迟。

Menu.setApplicationMenu(null),
&&
const updateErrorWindow = new BrowserWindow({autoHideMenuBar: true});

我使用的溶液在下面。现在这样比较好。

const window= new BrowserWindow({...});
window.setMenuBarVisibility(false);