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
#20
still strugling with this :s

i got this and it works with the exception that the frame opens in the bottom of the page after i resize it

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.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

            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)

            # 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.minsize(600, 600)
    w, h = root.winfo_screenwidth(), root.winfo_screenheight()
    root.geometry("%dx%d+0+0" % (w-550, h-250))
    root.title('Test')

    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 = 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)

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

    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()
[Image: 6e99ec442a2fea1bedb081e65e6e1534.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-25-2021, 11:27 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter destroy label inside labelFrame Nick_tkinter 3 4,638 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