Hi, i have this script but cant seem to open the browserframe in the correct place
import ctypes
import platform
from cefpython3 import cefpython as cef
from tkinter import *
import tkinter as tk
import sys
# platforms
WINDOWS = platform.system() == 'Windows'
LINUX = platform.system() == 'Linux'
MAC = platform.system() == 'Darwin'
class BrowserFrame(tk.Frame):
def __init__(self, master=None, **kw):
super().__init__(master, **kw)
self.browser = None
self.bind('<Configure>', self.on_configure)
def get_window_handle(self):
if MAC:
from AppKit import NSApp
import objc
return objc.pyobjc_id(NSApp.windows()[-1].contentView())
elif self.winfo_id() > 0:
return self.winfo_id()
else:
raise Exception('Could not obtain window handle!')
def on_configure(self, event):
if self.browser is None:
# create the browser and embed it in current frame
rect = [0, 0, self.winfo_width(), self.winfo_height()]
cef_winfo = cef.WindowInfo()
win_id = self.get_window_handle()
cef_winfo.SetAsChild(win_id, rect)
self.browser = cef.CreateBrowserSync(cef_winfo, url=urlset)
# start the browser handling loop
self.cef_loop()
# resize the browser
if WINDOWS:
ctypes.windll.user32.SetWindowPos(
self.browser.GetWindowHandle(), 0,
0, 0, event.width, event.height, 0x0002)
elif LINUX:
self.browser.SetBounds(0, 0, event.width, event.height)
def cef_loop(self):
cef.MessageLoopWork()
self.after(10, self.cef_loop)
def main():
sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error
root = tk.Tk()
root.minsize(600, 600)
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (w-550, h-250))
root.title('Test')
settings = {}
if MAC:
settings["external_message_pump"] = True
cef.Initialize(settings=settings)
leftfrm = LabelFrame(root, text="left frame for buttons with links", padx=5, pady=5, highlightbackground="black", highlightthickness=2)
leftfrm.grid(row=0, column=0, rowspan=99, sticky='nw', pady=2)
home_browser = LabelFrame(root, text="right frame for browser", padx=5, pady=5, highlightbackground="black", highlightthickness=2)
home_browser.grid(row=0, column=1, rowspan=99, sticky='ne', pady=2)
BrowserFrame(home_browser).grid(row=2, column=0, columnspan=9, sticky="ne")
for x in range(1, 25):
Label(leftfrm, text=str("Link "+str(x))).grid(row=x,column=0)
global urlset
urlset = "http://www.google.com"
root.mainloop()
if __name__ == '__main__':
main()
The browser only opens when i resize the window and not in the correct place.
Im using a Mac by the way.
thanks