" Teach you how to quickly develop desktop applications "
First of all, let’s imagine that we like a certain website, or we have a website ourselves. At a certain time we don’t know why we suddenly want to make a certain website our own desktop application (don’t ask why, not before, now we have ), then let's find a way to achieve our goal.
Clear purpose: we want to make our favorite website into a desktop program.
01—Thinking
We need to know what we need to do, we want to make the website into a desktop program, then we start to prepare.
1. A favorite website.
2. The python environment.
3. Like to use pip to install modules.
Let's think about it first, tk really wants to be able to make windows, is there a way to add a website to tk! But we did not find relevant information, so let's talk about another module.
pyqt5, is it possible to assume a website page?
Don't tell me, it's okay.
Then our goal becomes: how to embed the website into the desktop application developed by qt.
02—Development
To install the module:
Develop desktop application modules:
pip install PyQt5 == 5.10.0
Packaging tools:
pip install pyinstaller
Packaging commands
pyinstall -w -F + name
Look at the specific code:
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import *
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setWindowTitle("众里寻他千百度")#设置窗口名称,
self.setWindowIcon(QIcon('icon.png'))#设置窗口图标
self.resize(1000, 900)#设置默认窗口大小
self.showMaximized()#最大化
self.browser = QWebEngineView()
self.browser.load(QUrl('https://map.baidu.com/'))#设置默认网址
self.setCentralWidget(self.browser)
if __name__=='__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
Well, this is the end of the development. This is a desktop program for Baidu Maps, so let's package this program into a desktop program!
At this time, use the packaging command
pyinstall -w -F + name.py
Then we can see the desktop program we need under dist.
How to add WeChat friends in batches easily and quickly
WeChat applet---python interface writing
Learn more about Sao operations, welcome to follow us!