This has already been asked on the forum (that’s how I found this site in fact) but it wasn’t very specific and didn’t get good answers. So I thought I’d ask myself to hopefully get some better answers.
I’ll start by noting that I’m on Windows. Every single tutorial I’ve found thus fur is for Ubuntu or Mac. I can’t afford either.
I’m trying to build a simple web app for a website. I’ve found a module for this titled ‘pywebview’ but it seems to be very buggy. So I branched off and found this tutorial for building a good web browser. Problem is, it’s four years old. I tried to fix it, and I ended up with this:
def __init__(self): # Create window self.much_window = gtk.Window() self.much_window.set_icon_from_file('doge.png') self.much_window.connect('destroy', lambda w: gtk.main_quit()) self.much_window.set_default_size(360, 600) # Create navigation bar self.so_navigation = gtk.HBox() self.many_back = gtk.ToolButton(gtk.STOCK_GO_BACK) self.such_forward = gtk.ToolButton(gtk.STOCK_GO_FORWARD) self.very_refresh = gtk.ToolButton(gtk.STOCK_REFRESH) self.wow_address_bar = gtk.Entry() self.many_back.connect('clicked', self.go_back) self.such_forward.connect('clicked', self.go_forward) self.very_refresh.connect('clicked', self.refresh_page) self.wow_address_bar.connect('activate', self.load_page) self.so_navigation.pack_start(self.many_back, False) self.so_navigation.pack_start(self.such_forward, False) self.so_navigation.pack_start(self.very_refresh, False) self.so_navigation.pack_start(self.wow_address_bar) # Create view for webpage self.very_view = gtk.ScrolledWindow() self.such_webview = webkit.WebView() self.such_webview.open('http://brobin.me') self.such_webview.connect('title-changed', self.change_title) self.such_webview.connect('load-committed', self.change_url) self.very_view.add(self.such_webview) # Add everything and initialize self.wow_container = gtk.VBox() self.wow_container.pack_start(self.so_navigation, False) self.wow_container.pack_start(self.very_view) self.much_window.add(self.wow_container) self.much_window.show_all() gtk.main() def load_page(self, widget): so_add = self.wow_address_bar.get_text() if so_add.startswith('http://') or so_add.startswith('https://'): self.such_webview.open(so_add) else: so_add = 'http://' + so_add self.wow_address_bar.set_text(so_add) self.such_webview.open(so_add) def change_title(self, widget, frame, title): self.much_window.set_title('Wow So ' + title) def change_url(self, widget, frame): uri = frame.get_uri() self.wow_address_bar.set_text(uri) def go_back(self, widget): self.such_webview.go_back() def go_forward(self, widget): self.such_webview.go_forward() def refresh_page(self, widget): self.such_webview.reload()
Of course, I got an error because the tutorial was an Ubuntu and gi isn’t support on windows yet.
C:\Bots\Midlii>python main.py
Traceback (most recent call last):
File “main.py”, line 2, in
from gi.repository import Webview as webview
ImportError: No module named ‘gi’
The question is, how DO I build a webbrowser in Python3 in 2018? I’m not looking for anything complicated, like a back button, a search bar, or anything. I literally just want to display a website inside my program and not the web browser. I also need to inject CSS into said page, something which pywebview can’t do well (it also doesn’t allow you to hide the scrollbars, which I need to do), but I could probably try and find that out myself if it means just getting a good tutorial that works on Windows.