首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在python中加载Electron + EEL

如何在python中加载Electron + EEL
EN

Stack Overflow用户
提问于 2021-03-25 21:27:52
回答 1查看 427关注 0票数 1

我正在尝试使用EEL的电子浏览器。我的问题是电子无法加载index.html页面。

Python文件:

代码语言:javascript
运行
复制
import eel
import eel.browsers


eel.init('templates')


eel.browsers.set_path('electron', 'node_modules/electron/dist/electron')


eel.start('index.html', mode='electron' , port=8000  ,host='localhost',disable_cache=True, close_callback='close_callback', )

main.js

代码语言:javascript
运行
复制
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
const path = require('path')

function createWindow () {
  // Create the browser window.
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    }
  })

  // and load the index.html of the app.
  mainWindow.loadFile('http://localhost:8000/index.html')

  // Open the DevTools.
   mainWindow.webContents.openDevTools()
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
  createWindow()
  
  app.on('activate', function () {
    // On macOS it's common to re-create a window in the app when the
    // dock icon is clicked and there are no other windows open.
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
  })
})

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', function () {
  if (process.platform !== 'darwin') app.quit()
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

文件夹树:

如下图所示,电子无法定位索引,即使我正在制作电子从本地服务器加载。使用mainWindow.loadFile('http://localhost:8000/index.html')mainWindow.loadFile('http://localhost:8000/')

注意:我尝试在chrome浏览器中使用localhost:8000,它工作正常。

请帮帮我!

EN

回答 1

Stack Overflow用户

发布于 2021-03-26 01:06:09

我找到了我的问题的解决方案。这看起来很简单。但不管怎样,而不是mainWindow.loadFile('http://localhost:8000/') in main.js。使用mainWindow.loadURL('http://localhost:8000/')

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66800496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档