質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
JSON

JSON(JavaScript Object Notation)は軽量なデータ記述言語の1つである。構文はJavaScriptをベースとしていますが、JavaScriptに限定されたものではなく、様々なソフトウェアやプログラミング言語間におけるデータの受け渡しが行えるように設計されています。

Tkinter

Tkinterは、GUIツールキットである“Tk”をPythonから利用できるようにした標準ライブラリである。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

480閲覧

通貨変換アプリ(Tkinter)

beebear

総合スコア1

JSON

JSON(JavaScript Object Notation)は軽量なデータ記述言語の1つである。構文はJavaScriptをベースとしていますが、JavaScriptに限定されたものではなく、様々なソフトウェアやプログラミング言語間におけるデータの受け渡しが行えるように設計されています。

Tkinter

Tkinterは、GUIツールキットである“Tk”をPythonから利用できるようにした標準ライブラリである。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2022/03/31 16:14

編集2022/04/01 04:09

初質問の初心者です。よろしくお願いいたします。

実現したいこと

各国通貨を1ユーロ当たりの値に変換するアプリをTkinterで作成

発生している問題・エラーメッセージ

http://www.floatrates.com/daily/eur.json
上記のjsonを使用して、変換を行う関数とその結果を反映するところがまだ理解しておらず、手が止まっております。

該当のソースコード

python

1import tkinter as tk 2import tkinter.ttk as ttk 3from turtle import back 4 5win = tk.Tk() 6win.geometry('500x400') 7win.config(bg='lightgray') 8win.title('FX Lookup') 9 10label1 = tk.Label(win, text='Exchange Rate Lookup | Show exchange rates from EUR to various other currencies.', font=('Basic', 13), background='lightgray', wraplength=450, justify='left') 11label1.place(x=10, y=30) 12 13label2 = tk.Label(win, text='Example currency symbols: USD, HKD, INR, GBP, ...', font=('Basic', 13), background='lightgray') 14label2.place(x=10, y=95) 15 16separator_gray = ttk.Separator(win, style="gray.TSeparator", orient='horizontal') 17separator_gray.pack(padx=10, pady=160, fill='x') 18 19label3 = tk.Label(win, text='Currency symbol', font=('Basic', 13), background='lightgray') 20label3.place(x=175, y=170) 21 22label4 = tk.Label(win, text='1 EUR = ', background='lightgray', font=('Basic', 13)) 23label4.place(x=220, y=200) 24 25label5 = tk.Label(win, text=str(0), font=('Basic', 13), background='lightgray') 26label5.place(x=400, y=200) 27 28 29def convert(): 30 pass 31 32 33txtBox = tk.Entry(width=22, font=('Basic', 13)) 34txtBox.place(x=10, y=200) 35 36button = tk.Button(text="Lookup", command=convert, width=52, background='lightgray', font=('Basic', 13)) 37button.place(x=10, y=230) 38 39win.mainloop()

補足情報

python 3.10.4
Visual Studio Code 1.66.0
Windows 11

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

jpyのデータだけローカルに定義して動かしてみました。jpyだけ変換できます。
あとは、スクレイピング技術をつかって、jsonデータをダウンロードすればいいかと思います。

py

1import tkinter as tk 2import tkinter.ttk as ttk 3from turtle import back 4 5eur = { 6"jpy": {"code":"JPY","alphaCode":"JPY","numericCode":"392","name":"Japanese Yen","rate":136.02543829474,"date":"Thu, 31 Mar 2022 11:55:01 GMT","inverseRate":0.0073515660933451}, 7} 8 9win = tk.Tk() 10win.geometry('500x400') 11win.config(bg='lightgray') 12win.title('FX Lookup') 13 14label1 = tk.Label(win, text='Exchange Rate Lookup | Show exchange rates from EUR to various other currencies.', font=('Basic', 13), background='lightgray', wraplength=450, justify='left') 15label1.place(x=10, y=30) 16 17label2 = tk.Label(win, text='Example currency symbols: USD, HKD, INR, GBP, ...', font=('Basic', 13), background='lightgray') 18label2.place(x=10, y=95) 19 20separator_gray = ttk.Separator(win, style="gray.TSeparator", orient='horizontal') 21separator_gray.pack(padx=10, pady=160, fill='x') 22 23label3 = tk.Label(win, text='Currency symbol', font=('Basic', 13), background='lightgray') 24label3.place(x=175, y=170) 25 26label4 = tk.Label(win, text='1 EUR = ', background='lightgray', font=('Basic', 13)) 27label4.place(x=220, y=200) 28 29label5 = tk.Label(win, text=str(0), font=('Basic', 13), background='lightgray') 30label5.place(x=400, y=200) 31 32 33def convert(): 34 currency = txtBox.get().strip().lower() 35 if currency in eur: 36 label5['text'] = eur[currency]['rate'] 37 else: 38 label5['text'] = 'unknown' 39 40 41txtBox = tk.Entry(width=22, font=('Basic', 13)) 42txtBox.place(x=10, y=200) 43 44button = tk.Button(text="Lookup", command=convert, width=52, background='lightgray', font=('Basic', 13)) 45button.place(x=10, y=230) 46 47win.mainloop()

投稿2022/03/31 17:35

編集2022/03/31 17:38
shiracamus

総合スコア5406

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

beebear

2022/03/31 19:09

ありがとうございます! おかげさまで、何とか作成できました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問