figma2tkinter / app.py
5m4ck3r's picture
Update app.py
ccc1663 verified
import gradio as gr
import os
import subprocess
import zipfile
from pathlib import Path
def process_figma(figma_url, figma_token):
if not Path("Tkinter-Designer").exists():
subprocess.run(["git", "clone", "https://github.com/ParthJadhav/Tkinter-Designer.git"], check=True)
print("Cloning to the github repo")
os.chdir("Tkinter-Designer")
conversion_command = [
"python",
"-m",
"tkdesigner.cli",
figma_url,
figma_token
]
subprocess.run(conversion_command, check=True)
zip_file_path = "output.zip"
with zipfile.ZipFile(zip_file_path, 'w') as zip_file:
for foldername, subfolders, filenames in os.walk("build"):
for filename in filenames:
filepath = os.path.join(foldername, filename)
zip_file.write(filepath, os.path.relpath(filepath, "build"))
return zip_file_path
with gr.Blocks() as demo:
gr.Markdown("## Figma to Tkinter Converter") # Title
with gr.Row():
url_input = gr.Textbox(label="Figma URL")
token_input = gr.Textbox(label="Figma Token")
submit_button = gr.Button("Convert")
output_file = gr.File(label="Download Output")
submit_button.click(fn=process_figma, inputs=[url_input, token_input], outputs=output_file)
gr.Markdown(
"""
Upload your Figma design by providing the URL and token.
<br>
### Naming is Important
| Figma Element Name | Tkinter Element |
| --- | --- |
| Button | Button |
| Line | Line |
| Text | Name it anything |
| Rectangle | Rectangle |
| TextArea | Text Area |
| TextBox | Entry |
| Image | Canvas.Image() |
| ButtonHover (EXPERIMENTAL) | Button shown on hover |
<br>
**NOTE** : This project is created by : ParthJadhav
Checkout this repo to know more : [GitHub Repo](https://github.com/ParthJadhav/Tkinter-Designer)
"""
)
demo.launch()