I'm working at a project in Python3 in which i have both tkinter and a frame in tkinter with cef browser. This is the code.
from tkinter import messagebox
#import threading
from cefpython3 import cefpython as cef
import platform
import sys
from tkinter import *
import time
def on_closing ():
print('closing')
r.destroy()
cef.Shutdown()
r = Tk()
r.geometry('800x600')
r.protocol('WM_DELETE_WINDOW', on_closing)
f = Frame(r, bg = 'blue', height = 200)
f.pack(side = TOP, fill = 'x')
g=Frame(r,bg = 'white',height = 200)
g.pack(side = TOP, fill = 'x')
b1 = Button (g,text='Exit',command = on_closing)
b1.pack (side = LEFT)
b2 = Button (g,text='Show something',command = lambda:messagebox.showinfo('TITLE', 'Shown something'))
b2.pack (side = RIGHT)
sys.excepthook = cef.ExceptHook
rect = [0, 0, 800, 200]
print('browser: ', rect[2],'x',rect[3])
window_info=cef.WindowInfo(f.winfo_id())
window_info.SetAsChild(f.winfo_id(),rect)
cef.Initialize()
browser = cef.CreateBrowserSync(window_info, url='http://www.google.com')
r.update()
cef.MessageLoop()
##_thread = threading.Thread(target=cef.MessageLoop)
##
##_thread.start()
##
##_thread.join()
r.mainloop()
print('end')
The problem is:
- I leave cef.MessageLoop() and the browser works but buttons don't.
- I comment out cef.MessageLoop() and the browser doesn't work but tkinter window does.
I was thinking that maybe threading module wuold help but i tried (you can see the commented lines) and doesn't work (i get no exceptions but browser don't work). How can i sort this out?