CoolFace
Apppublic

LogicSpine/figma2tkinter

sourceHugging Faceupdated 2y agoView on Hugging Face
1likes
app.py69 linesDownload Raw Back to root
1import gradio as gr2import os3import subprocess4import zipfile5from pathlib import Path6 7def process_figma(figma_url, figma_token):8    if not Path("Tkinter-Designer").exists():9        subprocess.run(["git", "clone", "https://github.com/ParthJadhav/Tkinter-Designer.git"], check=True)10        print("Cloning to the github repo")11    12    os.chdir("Tkinter-Designer")13    conversion_command = [14        "python",15        "-m",16        "tkdesigner.cli",17        figma_url,18        figma_token19    ]20 21    subprocess.run(conversion_command, check=True)22    zip_file_path = "output.zip"23    with zipfile.ZipFile(zip_file_path, 'w') as zip_file:24        for foldername, subfolders, filenames in os.walk("build"):25            for filename in filenames:26                filepath = os.path.join(foldername, filename)27                zip_file.write(filepath, os.path.relpath(filepath, "build"))28    29    return zip_file_path30 31with gr.Blocks() as demo:32    gr.Markdown("## Figma to Tkinter Converter")  # Title33 34    with gr.Row():35        url_input = gr.Textbox(label="Figma URL")36        token_input = gr.Textbox(label="Figma Token")37 38    submit_button = gr.Button("Convert")39    output_file = gr.File(label="Download Output")40 41    submit_button.click(fn=process_figma, inputs=[url_input, token_input], outputs=output_file)42 43    gr.Markdown(44        """45        Upload your Figma design by providing the URL and token.46        <br>47 48        ### Naming is Important49 50        | Figma Element Name | Tkinter Element |51        | --- | --- |52        | Button | Button |53        | Line | Line |54        | Text | Name it anything |55        | Rectangle | Rectangle |56        | TextArea | Text Area |57        | TextBox | Entry |58        | Image | Canvas.Image() |59        | ButtonHover (EXPERIMENTAL) | Button shown on hover |60 61        <br>62 63        **NOTE** : This project is created by : ParthJadhav64 65        Checkout this repo to know more : [GitHub Repo](https://github.com/ParthJadhav/Tkinter-Designer)66        """67    )68 69demo.launch()