Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying Websites with Python

Tags:

python

I am making an os in python, but I need a web browser. Currently I am using the os.startfile method to launch chrome, but I want another way. I want a program that a user can enter a webpage and displaying the web page without using chrome, firefox, safari etc.

Here is the basic framework I have:

from tkinter import *
import webbrowser as wb
window = Tk()
window.configure(bg="Dark Red")
window.geometry("1000x1000")
window.title("Hyper Web Browser")
window.iconbitmap("icon.ico")
''' Defined Functions'''


def submit_url():
  wb.open_new_tab(Address_Bar.get())
  file2write = open("History.txt", "a")
  file2write.write(["\n", Address_Bar.get()])
  return submit_url
  '''Objects'''
  Address_Bar = Entry(
    bg="White",
    bd=0,
    font=("Comic", 25),
    width=100
  )
  Tab_1 = Label(
    bg="Red",
    bd=0,
    width=20,
    height=3
  )
  Return = Button(
    command=submit_url()
  )
  Address_Bar.place(x=20, y=60)
  Tab_1.place(x=0, y=0)
  Return.pack()

window.mainloop()

However, this program launches the web page into the user's default browser. Hence, I want to display the web page without using any other web browsers.

like image 623
NeelJ 83 Avatar asked Sep 13 '25 02:09

NeelJ 83


1 Answers

Here is a simpler version of webbrowser using PyQt5 :

import sys
from PyQt5 import QtWidgets,QtGui,QtCore
from PyQt5.QtWebEngineWidgets import *
app=QtWidgets.QApplication(sys.argv)
w=QWebEngineView()
w.load(QtCore.QUrl('https://google.com')) ## load google on startup
w.showMaximized()
app.exec_()

You can now add different widgets to it . In python you have two most common ways to make a webbrowser 1. by using gtk webkit 2. by QtWebEngine under PyQt5.

Webkit is based upon Safari while QtWebEngine is based on Chromium. You can decide which one suits you the best. Hope it helps.

like image 60
Anmol Gautam Avatar answered Sep 14 '25 16:09

Anmol Gautam