Oct-25-2021, 05:51 PM
I think this may be a tkinter layout problem. What is the location and size of the BrowserFrame?
[Tkinter] can i had a cefpython3 to a labelframe
|
Oct-25-2021, 05:51 PM
I think this may be a tkinter layout problem. What is the location and size of the BrowserFrame?
Oct-26-2021, 04:27 PM
(Oct-25-2021, 05:51 PM)deanhystad Wrote: I think this may be a tkinter layout problem. What is the location and size of the BrowserFrame? i think thats the issue, its not pointing to the frame and so it load width and height =0 i think the issue is here rect = [0, 0, self.winfo_width(), self.winfo_height()] it prints 140339762794416 [0, 0, 1, 1] i think its because the browser windows is not set properly, the self points to .!labelframe2.!browserframe if i replace rect = [0, 0, self.winfo_width(), self.winfo_height()] for rect = [0, 0, 300,200] it opens, so the issue is that the browser frame is set to 0,0 also, doing this opens but not in the correct LabelFrame(home_browser) also this might help print(win_id, rect) -> 140276467161232 [5, 5, 1, 1] print(self) -> .!labelframe2.!browserframe print(cef_winfo) -> <cefpython_py39.WindowInfo object at 0x7f94ac924220> print(event) -> <Configure event x=9 y=25 width=1 height=1>
Oct-26-2021, 06:08 PM
I removed all the cef stuff.
import tkinter as tk import sys class BrowserFrame(tk.LabelFrame): def __init__(self, *args, **kwargs): super().__init__(*args, text='Browser', **kwargs) self.bind('<Configure>', self.on_configure) def winfo_id(self): return super.winfo_id() def on_configure(self, event): print('on_configure', event.width, event.height) def main(): root = tk.Tk() leftfrm = tk.LabelFrame(root, text="Left", padx=5, pady=5, bg='red') leftfrm.grid(row=0, column=0, rowspan=99, sticky='nw', pady=2) home_browser = tk.LabelFrame(root, text="Home", padx=5, pady=5, bg='blue') home_browser.grid(row=0, column=1, rowspan=99, sticky='ne', pady=2) browser_frame = BrowserFrame(home_browser, bg='green') browser_frame.grid(row=1, column=0, sticky=(tk.N + tk.S + tk.E + tk.W)) for x in range(1, 25): tk.Label(leftfrm, text=f"Link {x}", bg='yellow').grid(row=x,column=0) root.mainloop() if __name__ == '__main__': main()When I run this I don't see the blue browser frame and I don't see the window size printed when I resize the window. In fact I only see the window size printed once, when the window is created. Look familiar?The reason for the lack of window configure events, and the small window size, is that you have not told the windows how they are supposed to resize their respective grids. I'll add in some lines to do that. import tkinter as tk import sys class BrowserFrame(tk.LabelFrame): def __init__(self, parent=None, **kwargs): super().__init__(parent, text='Browser', **kwargs) self.parent = parent self.bind('<Configure>', self.on_configure) def winfo_id(self): return super.winfo_id() def on_configure(self, event): print(self.winfo_width(), self.winfo_height()) def main(): root = tk.Tk() 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=0, sticky=('news')) for x in range(1, 25): tk.Label(leftfrm, text=f"Link {x}", bg='yellow').grid(row=x, column=0) root.columnconfigure(0, weight=1) root.columnconfigure(1, weight=5) root.rowconfigure(0, weight=1) home_browser.columnconfigure(0, weight=1) home_browser.rowconfigure(0, weight=1) root.mainloop() if __name__ == '__main__': main()Now I see the blue browser frame and I see the window size printed when I resize the window. If you add the row/column configure to your program it should work.
Oct-27-2021, 08:46 AM
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())->
![]() (Aug-28-2021, 09:03 PM)Yoriz Wrote: cefpython has a tkinter exampleBrooooo, can you help me? I don't know if this forum is alive or not, but I really need your help. When I try to drag a tkinter window with the "cefpython3" library, I get window "jerking" and the window does not move correctly. I took the code from the example from GitHub, which you left. I can give some information about what I "dug" in the GitHub code.
Sep-15-2023, 01:38 PM
(This post was last modified: Sep-19-2023, 04:12 AM by Larz60+.
Edit Reason: deleted spam link
)
(Aug-31-2021, 11:57 AM)deanhystad Wrote: The browser is not a tkinter widget. It cannot be added to a label frame. You need a specialized widget that understands how to host a browser window. That is what the example shows, and it shows it in a fairly concise manner. If there was a two step process for displaying a browser in tkinter don't you think the example would show that? Solid advice here. It's always good to start with working example code before diving into integrating it into your own project. The nuances of hosting a browser window in a Tkinter app are not straightforward, so leaning on a tried-and-true example can save you a lot of headaches. I totally agree that running the example as-is should be the first step. It'll give you a good sense of what to expect and help you decide if that's the direction you want to go for your project. |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
tkinter destroy label inside labelFrame | Nick_tkinter | 3 | 6,064 |
Sep-17-2023, 03:38 PM Last Post: munirashraf9821 |
|
Issue in Tkinter with winfo_class() and LabelFrame | ReDefendeur | 1 | 3,447 |
Oct-05-2020, 05:52 AM Last Post: Jeff900 |