Generating a Desktop Utility with AI: From Requirements to a Running Program

    This article documents a practical experiment in using large language models to generate a moderately complex desktop application. By tasking an AI with building a batch video-to-audio extraction tool using Python and tkinter, the author evaluates the model's software engineering capabilities. The piece covers requirement design, prompt engineering, the generation process, and the technical implementation of multithreading to prevent UI freezes, concluding with key reflections on how to effectively leverage AI for coding tasks.

    1. Background: From Code Generation to Software Delivery

    Recently, the progress of new open-source large language models (LLMs) in code generation has been remarkable. Various models are continually improving their benchmark scores, approaching the level of leading closed-source models. As a developer, my primary concern is not benchmark scores but a practical question: If I ask AI to write a “somewhat complex” desktop software, can the generated code run directly?

    To verify this, I designed a test task close to real-world scenarios: building a batch video-to-audio extraction tool using Python and tkinter. This type of task seems simple but actually covers multiple areas prone to pitfalls, such as GUI programming, multithreading, external process invocation, and exception handling. It is highly suitable for testing a model’s true engineering capabilities.

    2. Requirement Design: Stress-Testing the AI

    The first step of the test was to make the requirements tough. If I simply said “write an audio extraction tool,” any model could output a runnable piece of toy code. The real test lies in requirement density. I listed six demands at once:

    1. Format Coverage: Support common video input formats and export to mainstream audio formats like MP3 and WAV;
    2. Tech Stack Constraint: Use Python and the tkinter framework;
    3. Functional Completeness: Include core modules like file import lists and input/output format settings;
    4. Operational Loop: Complete functional chains including file import, conversion execution, and program exit;
    5. UI Quality: Reasonable layout and user-friendly interaction;
    6. Engineering Details: Must feature a progress bar and status bar, display error prompts, and must not freeze the UI.

    The sixth point is crucial. Anyone familiar with GUI programming knows that the “no freezing” requirement alone can eliminate a large number of lazy generation solutions. If time-consuming conversion tasks are written directly into the main thread, the interface will freeze, leaving users staring at a “Not Responding” window. This is the most common pitfall for beginners and the best test of a model’s true skill.

    3. Prompt Engineering: Translating Requirements into Model Instructions

    When writing the prompt, I followed several principles:

    Structured Expression: Instead of piling up long paragraphs in natural language, I listed functional points, non-functional points, and acceptance criteria by module, allowing the model to implement them one by one.

    Explicit Technical Constraints: I clearly specified the language version, GUI framework, whether third-party libraries were allowed, and external dependencies, preventing the model from improvising and causing environment incompatibility.

    Pre-embedded Engineering Requirements: For example, “time-consuming tasks must not block the main thread” and “conversion failures must provide readable error messages.” The more specific these requirements are, the higher the engineering quality of the generated code.

    An excerpt is shown below:

    1. [Task] Develop a batch video-to-audio extraction tool (Python + tkinter)
    2. [Features]
    3. - Support batch import of video files and display in a list
    4. - Selectable output formats: MP3 / WAV
    5. - Display progress bar and status bar during conversion
    6. [Engineering Requirements]
    7. - Conversion tasks run in a child thread; blocking the UI main thread is prohibited
    8. - Child thread updates UI via a queue; direct cross-thread control operation is prohibited
    9. - Pop up error prompt on conversion failure without interrupting batch tasks
    10. [Acceptance Criteria] Runs successfully on the first try, no errors, UI remains responsive throughout

    4. Generation Process: First-Pass Success with Zero Errors

    After submitting the prompt, the model skipped unnecessary pleasantries and went straight into the workflow: writing code, performing syntax validation, checking the runtime environment, and finally attaching a feature description.

    When the code was presented, I was honestly a bit surprised. It not only fulfilled the requirement list item by item but also proactively completed details I hadn’t specified:

    • Recursive Directory Scanning: Automatically recognizes video files recursively when importing a folder;
    • Format Expansion: Extended support for common video and audio formats;
    • Anti-Overwrite Mechanism: Automatically appends a number to output files with the same name to prevent mutual overwriting during batch conversion;
    • Dependency Pre-check: Automatically detects if ffmpeg is installed before conversion. If missing, it provides installation guidance in advance instead of throwing an error halfway through the run.

    These details mark the watershed between “runnable” and “user-friendly.” The ffmpeg pre-check, in particular, is often overlooked by many hand-written tools, leaving users baffled when conversions fail.

    More importantly, the code passed validation on the first try with zero errors.

    5. Preventing UI Freezes with Multithreading: How It Works

    Breaking down the generated code, the anti-freeze implementation approach is highly standard and worth elaborating on.

    Core Architecture: The main thread is only responsible for UI rendering and event response. Conversion tasks are placed in a threading.Thread child thread. The child thread passes progress messages to the main thread via a queue.Queue, and the main thread uses after() to periodically poll the queue and refresh the progress bar and status bar.

    1. import threading, queue
    2. def worker(files, fmt, q):
    3. for i, f in enumerate(files):
    4. try:
    5. convert(f, fmt)
    6. q.put(("progress", i + 1))
    7. except Exception as e:
    8. q.put(("error", f"{f}: {e}"))
    9. q.put(("done", None))
    10. # Main thread polling
    11. def poll():
    12. try:
    13. while True:
    14. kind, msg = q.get_nowait()
    15. if kind == "progress":
    16. update_progress(msg)
    17. elif kind == "error":
    18. show_error(msg)
    19. elif kind == "done":
    20. return
    21. except queue.Empty:
    22. pass
    23. root.after(100, poll)

    This pattern is the classic solution for tkinter multithreaded programming. The difficulty lies not in the code itself, but in the model proactively realizing that it should use a queue as an intermediary rather than directly manipulating controls across threads. The latter is undefined behavior in tkinter and highly prone to random crashes.

    6. Validation and Reflections: The Right Way to Approach AI Coding

    Through this practice, I summarized a few key takeaways:

    1. Requirement density determines output quality. Vague requirements only yield mediocre code. By writing acceptance criteria (zero errors, no freezing, progress feedback) into the prompt, the model will strive towards that standard.

    2. Engineering constraints must be explicitly stated. Instead of hoping the model intuitively knows requirements like “child thread execution,” “queue communication,” and “dependency pre-check,” it is better to state them in black and white. Once stated, mainstream models can generally implement them correctly.

    3. Manual validation cannot be omitted. Passing syntax validation does not mean the logic is correct. Edge cases (empty files, corrupted files, extremely long filenames) still require manually constructed test cases. AI drastically compresses the “0 to 80%” process, but the remaining 20% still requires developer oversight.

    4. Proactive completion capability is the watershed. A good model doesn’t just follow instructions blindly; it also fills in gaps based on engineering common sense—recursive scanning, anti-overwrite mechanisms, dependency checks, and more. When judging a model’s coding ability, looking at what it does extra is often more revealing than looking at what it did right.

    7. Conclusion

    The conclusion from this test is clear: The current code generation capabilities of mainstream LLMs are sufficient to support the complete delivery of a runnable software from a simple requirement, at least in the context of moderately complex desktop utilities. For developers, rather than agonizing over whether AI will replace programmers, it is better to master the three skills of requirement decomposition, prompt engineering, and code validation as early as possible. These dictate the ceiling of AI programming, while AI’s role is to free us from repetitive labor.