欧美精品123_精品露脸国产偷人在视频_日韩美女免费线视频_成人av三级

匯率轉(zhuǎn)換器(匯率轉(zhuǎn)換器歐元)

前沿拓展:


匯率轉(zhuǎn)換器(匯率轉(zhuǎn)換器歐元)

Python為開發(fā)GUI(圖形用戶界面)提供了多種選項。在所有的GUI方法中,tkinter是最常用的方法。它是Python附帶的Tk GUI工具包的標(biāo)準(zhǔn)Python接口。Python with tkinter是創(chuàng)建GUI應(yīng)用程序的最快和最簡單的方法。

創(chuàng)建一個tkinter

1)導(dǎo)入模塊tkinter

2)創(chuàng)建主窗口(容器)

3)將任意數(shù)量的小部件添加到主窗口。

4)將事件觸發(fā)器應(yīng)用于小部件。

讓我們創(chuàng)建一個基于GUI的簡單實時貨幣轉(zhuǎn)換器,該轉(zhuǎn)換器可以將金額從一種貨幣轉(zhuǎn)換為另一種貨幣。

所需模塊

tkinter
requests
json

下面是實現(xiàn):

# import all functions from the tkinter
from tkinter import *

# Create a GUI window
root = Tk()

# create a global variables
variable1 = StringVar(root)
variable2 = StringVar(root)

# initialise the variables
variable1.set("currency")
variable2.set("currency")

# Function to perform real time conversion
# from one currency to another currency
def RealTimeCurrencyConversion():

# importing required libraries
import requests, json

# currency code
from_currency = variable1.get()
to_currency = variable2.get()

# enter your api key here
api_key = "Your_Api_Key"

# base_url variable store base url
base_url = r"https://www.alphavantage.co/query?function = CURRENCY_EXCHANGE_RATE"

# main_url variable store complete url
main_url = base_url + "&from_currency =" + from_currency +
"&to_currency =" + to_currency + "&apikey =" + api_key

# get method of requests module
# return response object
req_ob = requests.get(main_url)

# json method return json format
# data into python dictionary data type.

# result contains list of nested dictionaries
result = req_ob.json()

# parsing the required information
Exchange_Rate = float(result["Realtime Currency Exchange Rate"]
['5. Exchange Rate'])

# get method of Entry widget
# returns current text as a
# string from text entry box.
amount = float(Amount1_field.get())

# calculation for the conversion
new_amount = round(amount * Exchange_Rate, 3)

# insert method inserting the
# value in the text entry box.
Amount2_field.insert(0, str(new_amount))

# Function for clearing the Entry field
def clear_all() :
Amount1_field.delete(0, END)
Amount2_field.delete(0, END)

# Driver code
if __name__ == "__main__" :

# Set the background colour of GUI window
root.configure(background = 'light green')

# Set the configuration of GUI window (WidthxHeight)
root.geometry("400×175")

# Create welcome to Real Time Currency Convertor label
headlabel = Label(root, text = 'welcome to Real Time Currency Convertor',
fg = 'black', bg = "red")

# Create a "Amount :" label
label1 = Label(root, text = "Amount :",
fg = 'black', bg = 'dark green')

# Create a "From Currency :" label
label2 = Label(root, text = "From Currency",
fg = 'black', bg = 'dark green')

# Create a "To Currency: " label
label3 = Label(root, text = "To Currency :",
fg = 'black', bg = 'dark green')

# Create a "Converted Amount :" label
label4 = Label(root, text = "Converted Amount :",
fg = 'black', bg = 'dark green')

# grid method is used for placing
# the widgets at respective positions
# in table like structure .
headlabel.grid(row = 0, column = 1)
label1.grid(row = 1, column = 0)
label2.grid(row = 2, column = 0)
label3.grid(row = 3, column = 0)
label4.grid(row = 5, column = 0)

# Create a text entry box
# for filling or typing the information.
Amount1_field = Entry(root)
Amount2_field = Entry(root)

# ipadx keyword argument set width of entry space.
Amount1_field.grid(row = 1, column = 1, ipadx ="25")
Amount2_field.grid(row = 5, column = 1, ipadx ="25")

# list of currency codes
CurrenyCode_list = ["INR", "USD", "CAD", "CNY", "DKK", "EUR"]

# create a drop down menu using OptionMenu function
# which takes window name, variable and choices as
# an argument. use * befor the name of the list,
# to unpack the values
FromCurrency_option = OptionMenu(root, variable1, *CurrenyCode_list)
ToCurrency_option = OptionMenu(root, variable2, *CurrenyCode_list)

FromCurrency_option.grid(row = 2, column = 1, ipadx = 10)
ToCurrency_option.grid(row = 3, column = 1, ipadx = 10)

# Create a Convert Button and attached
# with RealTimeCurrencyExchangeRate function
button1 = Button(root, text = "Convert", bg = "red", fg = "black",
command = RealTimeCurrencyConversion)

button1.grid(row = 4, column = 1)

# Create a Clear Button and attached
# with delete function
button2 = Button(root, text = "Clear", bg = "red",
fg = "black", command = clear_all)
button2.grid(row = 6, column = 1)

# Start the GUI
root.mainloop()

輸出

匯率轉(zhuǎn)換器(匯率轉(zhuǎn)換器歐元)

匯率轉(zhuǎn)換器(匯率轉(zhuǎn)換器歐元)

拓展知識:

匯率轉(zhuǎn)換器

http://www.ruan8.com/soft_11283.html 我用過的挺好用的今日匯率是一款實時匯率查詢工具,軟件啟動需要開啟網(wǎng)絡(luò),從而獲取實時的匯率資料。軟件提供29種常用貨幣間的轉(zhuǎn)換和匯率查詢!
軟件使用方法:
1.在“貨幣一”框中選擇原貨幣,在“貨幣二”中選擇將要轉(zhuǎn)換的貨幣!
2.輸入轉(zhuǎn)換的數(shù)額,點擊“計算”鍵即可進行轉(zhuǎn)換!
3.點擊箭頭可以交換兩個選擇框的數(shù)據(jù),從而進行逆轉(zhuǎn)換!

本回答被網(wǎng)友采納

原創(chuàng)文章,作者:九賢互聯(lián)網(wǎng)實用分享網(wǎng)編輯,如若轉(zhuǎn)載,請注明出處:http://www.uuuxu.com/20220901468516.html

主站蜘蛛池模板: 安福县| 绥江县| 彭泽县| 峨眉山市| 广昌县| 壶关县| 炉霍县| 深泽县| 南漳县| 高阳县| 海南省| 屏东市| 偃师市| 英山县| 丹江口市| 达州市| 资源县| 井冈山市| 抚州市| 司法| 宜兰市| 中宁县| 临颍县| 临安市| 鸡泽县| 常州市| 城固县| 华安县| 任丘市| 偏关县| 轮台县| 满城县| 井研县| 同仁县| 合作市| 泊头市| 南宁市| 柳河县| 闸北区| 城口县| 封开县|