from pyscript import Element def show_journal_entry(): debit_account = Element("debit_account").element.value debit_amount = Element("debit_amount").element.value credit_account = Element("credit_account").element.value credit_amount = Element("credit_amount").element.value journal_entry = f''' 借方: {debit_account} {debit_amount}円 貸方: {credit_account} {credit_amount}円 ''' display(journal_entry, target="journal_entry") return journal_entry def save_journal_entry(): journal_entry = show_journal_entry() filename = "journal_entry.txt" with open(filename, 'w') as file: file.write(journal_entry.strip()) # ダウンロードリンクを作成してクリックする from pyodide.ffi import create_proxy import js def trigger_download(): link = js.document.createElement("a") link.href = js.URL.createObjectURL(js.Blob.new([journal_entry], {type: "text/plain"})) link.download = filename link.click() trigger_download_proxy = create_proxy(trigger_download) js.setTimeout(trigger_download_proxy, 0)