国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁/技術文章
文章詳情頁

python 實現一個圖形界面的匯率計算器

瀏覽:2日期:2022-07-06 08:32:53

調用的api接口:

https://api.exchangerate-api.com/v4/latest/USD

python 實現一個圖形界面的匯率計算器

完整代碼

import requestsfrom tkinter import *import tkinter as tkfrom tkinter import ttkclass RealTimeCurrencyConverter(): def __init__(self,url): self.data = requests.get(url).json() self.currencies = self.data[’rates’] def convert(self, from_currency, to_currency, amount): initial_amount = amount if from_currency != ’USD’ : amount = amount / self.currencies[from_currency] amount = round(amount * self.currencies[to_currency], 4) return amountclass App(tk.Tk): def __init__(self, converter): tk.Tk.__init__(self) self.title = ’Currency Converter’ self.currency_converter = converterself.geometry('500x200') self.intro_label = Label(self, text = ’Welcome to Real Time Currency Convertor’, fg = ’blue’, relief = tk.RAISED, borderwidth = 3) self.intro_label.config(font = (’Courier’,15,’bold’)) self.date_label = Label(self, text = f'1 Indian Rupee equals = {self.currency_converter.convert(’INR’,’USD’,1)} USD n Date : {self.currency_converter.data[’date’]}', relief = tk.GROOVE, borderwidth = 5) self.intro_label.place(x = 10 , y = 5) self.date_label.place(x = 160, y= 50)valid = (self.register(self.restrictNumberOnly), ’%d’, ’%P’) self.amount_field = Entry(self,bd = 3, relief = tk.RIDGE, justify = tk.CENTER,validate=’key’, validatecommand=valid) self.converted_amount_field_label = Label(self, text = ’’, fg = ’black’, bg = ’white’, relief = tk.RIDGE, justify = tk.CENTER, width = 17, borderwidth = 3)self.from_currency_variable = StringVar(self) self.from_currency_variable.set('INR') self.to_currency_variable = StringVar(self) self.to_currency_variable.set('USD') font = ('Courier', 12, 'bold') self.option_add(’*TCombobox*Listbox.font’, font) self.from_currency_dropdown = ttk.Combobox(self, textvariable=self.from_currency_variable,values=list(self.currency_converter.currencies.keys()), font = font, state = ’readonly’, width = 12, justify = tk.CENTER) self.to_currency_dropdown = ttk.Combobox(self, textvariable=self.to_currency_variable,values=list(self.currency_converter.currencies.keys()), font = font, state = ’readonly’, width = 12, justify = tk.CENTER)self.from_currency_dropdown.place(x = 30, y= 120) self.amount_field.place(x = 36, y = 150) self.to_currency_dropdown.place(x = 340, y= 120)self.converted_amount_field_label.place(x = 346, y = 150) self.convert_button = Button(self, text = 'Convert', fg = 'black', command = self.perform) self.convert_button.config(font=(’Courier’, 10, ’bold’)) self.convert_button.place(x = 225, y = 135) def perform(self): amount = float(self.amount_field.get()) from_curr = self.from_currency_variable.get() to_curr = self.to_currency_variable.get() converted_amount = self.currency_converter.convert(from_curr,to_curr,amount) converted_amount = round(converted_amount, 2) self.converted_amount_field_label.config(text = str(converted_amount)) def restrictNumberOnly(self, action, string): regex = re.compile(r'[0-9,]*?(.)?[0-9,]*$') result = regex.match(string) return (string == '' or (string.count(’.’) <= 1 and result is not None))if __name__ == ’__main__’: url = ’https://api.exchangerate-api.com/v4/latest/USD’ converter = RealTimeCurrencyConverter(url) App(converter) mainloop()

運行效果:

python 實現一個圖形界面的匯率計算器

以上就是python 實現一個圖形界面的匯率計算器的詳細內容,更多關于python 匯率計算的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 九九九在线视频 | 日韩一区二区三区在线视频 | 久久国内精品自在自线软件 | 欧美高清强视频 | 免费一级肉体全黄毛片 | 97青娱国产盛宴精品视频 | 国产日韩精品一区二区 | 综合欧美视频一区二区三区 | 国产日比视频 | 国产黄色片网站 | 久久精品女人毛片国产 | 精品一区二区影院在线 | rion美乳弹出来四虎在线观看 | 欧美亚洲一区 | 扒开双腿猛进入喷水免费视频 | 99久久精彩视频 | a级毛片免费看 | 成人久久18免费游戏网站 | 欧美视频一区在线 | 国产一进一出视频网站 | 全国最大色成免费网站 | 亚洲精品一区二区三区 | 女人被男人躁得好爽免费视频免费 | 黄色毛片子 | 成人久久久久 | 亚洲福利影院 | 亚洲综合久久久久久中文字幕 | 亚洲成a人片在线观看中文 亚洲成a人片在线观看中文!!! | 手机av在线播放 | 国产成人v爽在线免播放观看 | 欧美满嘴射 | 日韩毛片高清免费 | 国产成人精品久久亚洲高清不卡 | 热伊人99re久久精品最新地 | 精品爱爱 | 亚洲精品国自产拍影院 | 国产精品久久视频 | 日韩美女网站在线看 | 欧美一区二区三区免费播放 | 99久久免费看精品国产一区 | 222aaa免费国产在线观看 |