Skip to Content
Python语言及其应用(第2版)
book

Python语言及其应用(第2版)

by Bill Lubanovic
March 2022
Intermediate to advanced
522 pages
13h 52m
Chinese
Posts & Telecom Press
Content preview from Python语言及其应用(第2版)
338
18
你可以直接使用该模块。下列程序会在浏览器中载入
Python
官方网站的主页:
>>> import webbrowser
>>> url = 'http://www.python.org/'
>>> webbrowser.open(url)
True
在新的浏览器窗口中打开:
>>> webbrowser.open_new(url)
True
在浏览器新标签中打开(如果浏览器支持标签的话):
>>> webbrowser.open_new_tab('http://www.python.org/')
True
webbrowser
可以控制浏览器完成所有工作。
18.5.2
webview
webview
会使用机器的本机
GUI
在自己的窗口中显示页面,而不是像
webbrowser
那样调用
浏览器。在
Linux
macOS
中安装,命令如下:
$
pip install pywebview[qt]
Windows
中安装,命令如下:
$
pip install pywebview[cef]
如果碰到问题,可以参考安装事项。
下面的例子展示了官方的美国政府当前时间站点:
>>> import webview
>>> url = input("URL? ")
URL? https://exl.ptpress.cn:8442/ex/l/36aeea0f
>>> webview.create_window(f"webview display of {url}", url)
18-1
显示了我得到的结果。
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano
Python实用技能学习指南

Python实用技能学习指南

Posts & Telecom Press, Robert Smallshire, Austin Bingham
Python技术基础视频教程

Python技术基础视频教程

保罗·J·戴特尔
Python面向对象编程指南

Python面向对象编程指南

Posts & Telecom Press, Steven F. Lott

Publisher Resources

ISBN: 9787115586223