def perform(self,):įrom_curr = om_currency_variable.get() The perform method will take the user input and convert the amount into the desired currency and display it on the converted_amount entry box. nvert_ace(x = 225, y = 135)Ĭommand = self.perform – It means on click it will call perform(). nvert_button = Button(self, text = "Convert", fg = "black", command = self.perform) Now Let’s add the CONVERT button which will call the perform function. nverted_amount_field_ace(x = 346, y = 150)Īfter the successful Execution of code till now. Self.to_currency_dropdown = ttk.Combobox(self, textvariable=self.to_currency_variable,values=list(self.currency_()), font = font, state = 'readonly', width = 12, justify = tk.CENTER) om_currency_dropdown = ttk.Combobox(self, textvariable=om_currency_variable,values=list(self.currency_()), font = font, state = 'readonly', width = 12, justify = tk.CENTER) Self.option_add('*TCombobox*Listbox.font', font) Self.to_currency_t("USD") # default value Self.to_currency_variable = StringVar(self) nverted_amount_field_label = Label(self, text = '', fg = 'black', bg = 'white', relief = tk.RIDGE, justify = tk.CENTER, width = 17, borderwidth = 3) Self.amount_field = Entry(self,bd = 3, relief = tk.RIDGE, justify = tk.CENTER,validate='key', validatecommand=valid) # restricNumberOnly function will restrict thes user to enter invavalid number in Amount field. Valid = (self.register(self.restrictNumberOnly), '%d', '%P') So That users can enter the amount and choose among currencies. Now let’s create the entry box for the amount and options of currency in the frame. After the execution of this part of code, our frame looks like something. Self.date_label = Label(self, text = f"1 Indian Rupee equals = ", relief = tk.GROOVE, borderwidth = 5)įirst, we set up the frame and add some info in it. Self.intro_label = Label(self, text = 'Welcome to Real Time Currency Convertor', fg = 'blue', relief = tk.RAISED, borderwidth = 3) Let’s Create the Converter self.geometry("500x200") To Create UI we will create a class Currenc圜onverterUI def _init_(self, converter):Ĭonverter: Currency Converter object which we will use to convert currencies. Now let’s create a UI for the currency converter To _currency: currency in which you want to convert.Īmount: how much amount you want to convert.Ĭonverter = RealTimeCurrenc圜onverter(url) # limiting the precision to 4 decimal placesĪmount = round(amount * self.currencies, 4)įrom_currency: currency from which you want to convert. #first convert it into USD if it is not in USD.Īmount = amount / self.currencies Convert() method: def convert(self, from_currency, to_currency, amount): json() will convert the page into the json file. Requests.get(url) load the page in our python program and then. Now we will create the Currenc圜onverter class which will get the real-time exchange rate and convert the currency and return the converted amount.ģ.1. Import the libraries:įor this project based on Python, we are using the tkinter and requests library. Rates: It is the exchange rate of currencies with base currency USD. which means to convert any currency we have to first convert it to USD then from USD, we will convert it in whichever currency we want.ĭate and time: It shows the last updated date and time. Here, we can see the data in JSON format, with the following details:īase – USD: It means we have our base currency USD. To get real-time exchange rates, we will use: To install the tkinter and requests library, type the following code in your terminal: pip install tkinterīefore proceeding ahead, please download source code of project: Currency Converter Project Code Steps to Build the Python Project on Currency Converter The currency converter project in python requires you to have basic knowledge of python programming and the pygame library. For a user interface, we are going to use the tkinter libraryĬurrency Converter in Python Prerequisites In this tutorial, we are going to build an exciting python project through which you can convert currencies. After tons of tutorials, practicals, interview questions, we are coming with a series of projects from beginner to advanced level. DataFlair is devoted to make you a successful Python Developer. Free Python course with 35 real-time projects Start Now!!Īre you looking to build a solid career in Python? If Yes, you have to work on projects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |