myweb.py 817 B

1234567891011121314151617181920212223242526272829303132
  1. from cefpython3 import cefpython as cef
  2. from tkinter import *
  3. import threading
  4. import sys
  5. # cefpython3 目前只支持python3.7,高版本Python不兼容
  6. def embed_browser_thread(frame, _rect):
  7. sys.excepthook = cef.ExceptHook
  8. window_info = cef.WindowInfo(frame.winfo_id())
  9. window_info.SetAsChild(frame.winfo_id(), _rect)
  10. cef.Initialize()
  11. cef.CreateBrowserSync(window_info, url='http://www.baidu.com')
  12. cef.MessageLoop()
  13. if __name__ == '__main__':
  14. root = Tk()
  15. root.geometry("800x600")
  16. frame1 = Frame(root, bg='blue')
  17. frame1.pack(side=TOP, fill=X)
  18. frame2 = Frame(root, bg='white')
  19. frame2.pack(side=TOP, fill=X)
  20. rect = [200, 200, 800, 200]
  21. thread = threading.Thread(target=embed_browser_thread, args=(frame1, rect))
  22. thread.start()
  23. root.mainloop()