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?
Have you tried running the example code? That would be my first step. Forget about your program for now and just try running the browser example as is. Does it work like you think? What happens when you resize the window, does the browse resize? Do you like navigation bar? Maybe you'll want that for your program too.
Once you have the example running think about how you can use the example code in your project. The example defines a specialized frame for housing a browser window. Your code can import the example as a module and use that class. Create an instance of "BrowserFrame" and pack it in your label frame. The example code adds the browser to the NavigationBar.
self.browser_frame = BrowserFrame(self, self.navigation_bar) self.browser_frame.grid(row=1, column=0, sticky=(tk.N + tk.S + tk.E + tk.W)) tk.Grid.rowconfigure(self, 1, weight=1) tk.Grid.columnconfigure(self, 0, weight=1)And the NavigationBar is added to the MainFrame (just a frame that fills the entire root window).
self.navigation_bar = NavigationBar(self) self.navigation_bar.grid(row=0, column=0, sticky=(tk.N + tk.S + tk.E + tk.W))If you don't want the Navigation bar I think you could just create an instance of BrowserFrame and add it to a LabelFrame.
label_frame = tk.LabelFrame(root, text='Browser') label_frame.grid(row=0, column=0, sticky=(tk.N + tk.S + tk.E + tk.W)) tk.Grid.rowconfigure(label_frame , 1, weight=1) tk.Grid.columnconfigure(label_frame , 0, weight=1) browser_frame = BrowserFrame(self, label_frame) browser_frame.grid(row=1, column=0, sticky=(tk.N + tk.S + tk.E + tk.W)) tk.Grid.rowconfigure(browser_frame , 1, weight=1) tk.Grid.columnconfigure(browser_frame , 0, weight=1)You probably won't need to make a scrollable frame because the browser will do that for you automatically. I have not run the example, so I don't know for sure
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.