2017-03-15 43 views
1

我在python中做了一个os,但我需要一个web浏览器。目前我正在使用os.startfile方法启动chrome,但我需要另一种方式。我想一个程序,用户可以输入一个网页,显示该网页不使用Chrome,Firefox和Safari等用Python显示网站

下面是基本的框架,我有:

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

不过,这一方案启动网页导入用户的默认浏览器。因此,我想在不使用任何其他Web浏览器的情况下显示网页。

+3

任何显示网页的程序都称为Web浏览器。您尝试实施您自己的Web浏览器。祝你好运。 – DyZ

+0

这可能是有用的:http://stackoverflow.com/questions/15138614/how-can-i-read-the-contents-of-an-url-with-python –

+0

添加到@DYZ评论。默认情况下,Tkinter没有任何HTML呈现功能。 – Vallentin

回答

1

下面是使用网页浏览器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_() 

现在可以不同的部件,将其添加。 在python中,有两种最常用的方式来制作webbrowser 1.通过在PyQt5下使用gtk webkit 2. by QtWebEngine。

Webkit基于Safari,而QtWebEngine基于Chromium。你可以决定哪一个最适合你。 。希望它有帮助。