Python Forum
[Tkinter] can i had a cefpython3 to a labelframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] can i had a cefpython3 to a labelframe
#24
i see thanks :)

i still need to resize manually for the window to open and it still is not opening in the frame, i think im missing something :s


import tkinter as tk
import sys
import ctypes
import platform
from cefpython3 import cefpython as cef
from tkinter import *
import tkinter as tk
import sys
# platforms
from cefpython.examples.tkinter_ import logger


WINDOWS = platform.system() == 'Windows'
LINUX = platform.system() == 'Linux'
MAC = platform.system() == 'Darwin'

class BrowserFrame(tk.LabelFrame):
    def __init__(self, master=None, **kw):
        super().__init__(master, text='Browser', **kw)
        self.parent = master
        self.bind('<Configure>', self.on_configure)
        super().__init__(master, **kw)
        self.browser = None
        self.bind('<Configure>', self.on_configure)

    def winfo_id(self):
        return super.winfo_id()

    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

            self.update()
            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)
            print(self.winfo_width(), self.winfo_height())
            # 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():
    root = tk.Tk()
    root.columnconfigure(0, weight=1)
    root.columnconfigure(1, weight=5)
    root.rowconfigure(0, weight=1)

    WindowUtils = cef.WindowUtils()
    sys.excepthook = cef.ExceptHook  # To shutdown all CEF processes on error
    settings = {}
    if MAC:
        settings["external_message_pump"] = True

    cef.Initialize(settings=settings)


    leftfrm = tk.LabelFrame(root, text="Left", padx=5, pady=5, bg='red')
    leftfrm.grid(row=0, column=0, sticky='news', pady=2)

    home_browser = tk.LabelFrame(root, text="Home", padx=5, pady=5, bg='blue')
    home_browser.grid(row=0, column=1, sticky='news', pady=2)

    browser_frame = BrowserFrame(home_browser, bg='green')
    browser_frame.grid(row=0, column=3, sticky=('news'))

    for x in range(1, 25):
        tk.Label(leftfrm, text=f"Link {x}", bg='yellow').grid(row=x, column=0)

    global urlset
    urlset = "http://www.google.com"



    home_browser.columnconfigure(0, weight=1)
    home_browser.rowconfigure(0, weight=1)
    root.mainloop()


if __name__ == '__main__':
    main()
it still print
print(self.winfo_width(), self.winfo_height()) 
->
Output:
1 576
[Image: Captura-de-ecra-2021-10-27-a-s-09-45-40.png]
Reply


Messages In This Thread
can i had a cefpython3 to a labelframe - by razs - Aug-28-2021, 10:47 AM
RE: can i had a cefpython3 to a labelframe - by razs - Oct-27-2021, 08:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter destroy label inside labelFrame Nick_tkinter 3 4,639 Sep-17-2023, 03:38 PM
Last Post: munirashraf9821
  Issue in Tkinter with winfo_class() and LabelFrame ReDefendeur 1 2,786 Oct-05-2020, 05:52 AM
Last Post: Jeff900

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020