cefpython_cefpython3

常用

pip install cefpython3

# coding=gbk

from cefpython3 import cefpython as cef

from flask import Flask

import ctypes

import tkinter as tk

import threading

import os

class Application(tk.Frame):

navigation_bar = None

def __init__(self, root):

root.geometry("900x640")

tk.Frame.__init__(self, root)

self.master.title("")

self.bind("", self.on_configure)

self.browser_frame = BrowserFrame(self, self.navigation_bar) # 浏览器框架

self.browser_frame.grid(row=1, column=0,sticky=(tk.N + tk.S + tk.E + tk.W))

tk.Grid.rowconfigure(self, 1, weight=1)

tk.Grid.columnconfigure(self, 0, weight=1)

self.pack(fill=tk.BOTH, expand=tk.YES) # 包装 Application

def on_configure(self, event):

if self.browser_frame:

width = event.width

height = event.height

if self.navigation_bar:

height = height - self.navigation_bar.winfo_height()

self.browser_frame.on_Application_configure(width, height)

class BrowserFrame(tk.Frame):

closing = False

browser = None

def __init__(self, master, navigation_bar=None):

self.navigation_bar = navigation_bar

tk.Frame.__init__(self, master)

self.bind("", self.on_configure)

def embed_browser(self):

window_info = cef.WindowInfo()

rect = [0, 0, self.winfo_width(), self.winfo_height()]

window_info.SetAsChild(self.get_window_handle(), rect)

self.browser = cef.CreateBrowserSync(

window_info,

url="file://{}".format(os.path.join(os.getcwd(), 'handsontable.html'))

)

self.message_loop_work()

def get_window_handle(self): # 获取窗口句柄

if self.winfo_id() > 0:

return self.winfo_id()

def message_loop_work(self): # 消息循环工作

cef.MessageLoopWork()

self.after(10, self.message_loop_work)

def on_configure(self, _): # 判断是否有 cef 对象

if not self.browser:

self.embed_browser()

def on_Application_configure(self, width, height): # cef 窗口大小

if self.browser:

pass

ctypes.windll.user32.SetWindowPos(self.browser.GetWindowHandle(),

0,0, 0, width, height, 0x0002)

def runserver():

app = Flask(__name__)

@app.route('/')

def index():

return '

233

'

app.run()

if __name__ == '__main__':

threading.Thread(target=runserver).start()

root = tk.Tk()

app = Application(root)

cef.Initialize()

app.mainloop()

cef.Shutdown()

os._exit(0)

检查更新

语法

返回值

作用

ver["version"]

66.0

CEF Python 版本

ver["chrome_version"]

66.0.3359.181

Chromium 版本

ver["cef_version"]

CEF 3.3359.1774.gd49d25f

CEF 版本

ver=platform.python_version()

arch=platform.architecture()[0]

Python 3.6.5

64bit

python 版本

位数

assert cef._version_ >= "57.0", "CEF Python v57.0+ required to run this"

CEF 版本是否大于 57 不大于抛异常

from cefpython3 import cefpython as cef

import platform

ver = cef.GetVersion()

print("[hello_world.py] CEF Python {ver}".format(ver=ver["version"]))

print("[hello_world.py] Chromium {ver}".format(ver=ver["chrome_version"]))

print("[hello_world.py] CEF {ver}".format(ver=ver["cef_version"]))

print("[hello_world.py] Python {ver} {arch}".format(ver=platform.python_version(),arch=platform.architecture()[0]))

assert cef.__version__ >= "57.0", "CEF Python v57.0+ required to run this"

打包

pip install pyinstaller

pip install pycrypto

python pyinstaller.py

1、安装 Microsoft Visual C++ 14.0 选择 Windows 8.1 SDK 功能

2、复制 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\stdint.h

3、粘贴 C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt

4、修改 C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\inttypes.h

#include

#include "stdint.h"

5、卸载 Micrsoft Visual C++ 14.0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值