Creating a Python Executable for Daily Inspirational Quotes Using EasyGUI and PyInstaller
This tutorial explains how to scrape daily inspirational or love quotes from a Chinese website with Python, display them using EasyGUI, and package the script into a standalone executable using PyInstaller, including troubleshooting tips for common packaging errors.
The article introduces a small Python program that fetches a random inspirational or love quote from a Chinese website, shows it in a pop‑up window via the easygui library, and explains how to turn the script into a standalone executable.
Web scraping step : The script uses requests to download the page https://www.duanwenxue.com/yulu/aiqingxuanyan/ , parses it with BeautifulSoup , extracts all anchor tags inside the div.list-short-article element, and selects one quote at random.
<code>import requests
import easygui
from bs4 import BeautifulSoup
import random
def getwords():
texts = []
url = 'https://www.duanwenxue.com/yulu/aiqingxuanyan/'
response = requests.get(url)
texts.append(response.text)
articles = []
for text in texts:
soup = BeautifulSoup(text, 'lxml')
arttis = soup.find('div', class_='list-short-article').find_all('a', {'target': "_blank"})
articles.extend([arttis[i].text.strip() for i in range(len(arttis))])
todaywords = articles[random.randint(0, len(articles)-1)]
return todaywords
if __name__ == '__main__':
path = 'biaobai.jpg'
easygui.msgbox(getwords(), "每日情话或每日励志", image=path)
</code>Packaging into an executable : After installing PyInstaller with pip install pyinstaller , run the command in the project directory to generate a dist folder containing the executable. The article notes that missing library errors may appear; reinstall the problematic library with pip and rebuild.
If the build succeeds, place any desired image (e.g., biaobai.jpg ) alongside the executable, and the program will display a random quote each time it runs.
The guide also provides screenshots of the source code, the web‑page inspection process, and the final executable folder, and invites readers to view the original article for more details.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.