Build a Python Lottery App in 5 Minutes with AI and Deploy to Alibaba Cloud SAE

This guide walks you through installing an IDE with an AI coding plugin, prompting the AI to generate a full-featured Tkinter lottery GUI, running it locally, and then repackaging it with Flask for deployment on Alibaba Cloud SAE, complete with step‑by‑step instructions and screenshots.

Alibaba Cloud Native
Alibaba Cloud Native
Alibaba Cloud Native
Build a Python Lottery App in 5 Minutes with AI and Deploy to Alibaba Cloud SAE

Overview

This guide shows how to use the Tongyi Lingma AI coding plugin to generate a Python lottery application, run it locally as a Tkinter GUI, and then convert it into a Flask web service that can be deployed on Alibaba Cloud Serverless App Engine (SAE).

Prerequisites

Python 3.x with pip Standard libraries: tkinter, Pillow Web libraries: Flask, Werkzeug Local IDE (e.g., VS Code) with the Tongyi Lingma AI coding extension installed and logged in to an Alibaba Cloud account

Desktop GUI project layout

Create a folder named lingma_reward. Place a background image named 底图.jpg (size 1400 × 800 px) inside the folder. The AI prompt (shown below) asks for a Tkinter‑based lottery system with the following requirements:

1. Technical requirements:
   - Use <code>tkinter</code> for the GUI
   - Use <code>PIL</code> (Pillow) to load the background image
   - Implement an object‑oriented design with a <code>LotterySystem</code> class
2. Layout:
   - Window size 1400 × 800
   - Background image at <code>lingma_reward/底图.jpg</code>
   - Central content area 550 × 450, fixed size, background color (250,250,250)
   - Buttons with image‑based background, black bold text
3. Core modules:
   - Participant initialization (total number, keyword‑generated list)
   - Lottery control (Start/Stop buttons, random scrolling, draw 3 winners)
   - History display of past winners
4. UI details:
   - Title "通义灵码抽奖系统" in Arial
   - Grey button background, large font for results, text box for history
5. Interaction logic:
   - Initialization required before starting
   - Disable Start while drawing, enable Stop
   - After Stop, record winners and remove them from the pool
   - Include error handling and user prompts

The AI returns a complete script (e.g., game2.py) that defines LotterySystem, builds the Tkinter window, handles participant input, runs the draw with a timed random selection, and updates the UI with results and history.

Running the desktop version

Save the generated code as game2.py and execute: python game2.py The application opens a window where you can enter the number of participants, start the draw, and view the three selected winners and the historical list.

Adapting to a Flask web service

Modify the original prompt to request a Flask implementation. The AI then produces the following project structure:

app/
├── app.py                # Flask entry point, creates a LotterySystem instance
├── static/
│   └── images/
│       └── 底图.jpg      # Same background image as the desktop version
├── templates/
│   └── index.html        # Jinja2 template rendering the UI
└── requirements.txt      # List of Python dependencies

Key points for the Flask version:

All logic remains inside a LotterySystem class.

HTTP endpoints expose initialization, start, stop, and history actions. requirements.txt should contain at least:

Flask==2.3.2
Werkzeug==2.3.2
Pillow==10.0.0

Packaging for Alibaba Cloud SAE

Compress the app directory into a ZIP file. In the SAE console:

Select “Create Application”, choose Python as the runtime.

Upload the ZIP package.

Set the startup command to python app/app.py (or the appropriate path).

Configure a public IP, HTTP port (default 80), and container port (matching the Flask app, typically 5000).

Enable usage‑based billing if desired.

After deployment, the service URL (public IP) can be opened in a browser to access the same lottery functionality via the web interface.

Important URLs

https://tongyi.aliyun.com/lingma/download

– Tongyi Lingma IDE plugin download

https://help.aliyun.com/zh/sae/serverless-app-engine-upgrade/user-guide/python-zip-packaging-instructions-2-0

– SAE Python ZIP packaging guide https://saenext.console.aliyun.com/ – Alibaba Cloud SAE console

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonAI code generationFlaskcloud deploymentTkinterlottery app
Alibaba Cloud Native
Written by

Alibaba Cloud Native

We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.