Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Sat Aug 19 16:25:46 2017
- @author: Anwar Goulouh
- """
- import requests
- from bs4 import BeautifulSoup
- from datetime import datetime
- import tkinter as tk
- #from tkinter import *
- #Make Window
- root = tk.Tk()
- root.geometry("612x417")
- root.title("Exchange Rates")
- root.resizable(0,0)
- root.configure(background='lightgrey')
- #End
- amountex = '1'
- def continuousUpdate():
- while amount == '0':
- results()
- def results():
- # while amount == '0':
- t = datetime.utcnow()
- url1 = "http://www.xe.com/currencyconverter/convert/" + "?Amount=" + amountex + "&From=" + cur1 + "&To=" + cur2
- url2 = "http://www.xe.com/currencyconverter/convert/" + "?Amount=" + amountex + "&From=" + cur2_1.get() + "&To=" + cur1_1.get()
- html_code1 = requests.get(url1).text
- html_code2 = requests.get(url2).text
- soup1 = BeautifulSoup(html_code1, 'html.parser')
- soup2 = BeautifulSoup(html_code2, 'html.parser')
- rate1 = soup1.find('span', {'class', 'uccResultAmount'})
- rate2 = soup2.find('span', {'class', 'uccResultAmount'})
- lblfrmex_text.set(rate1.contents[0])
- lbltoex_text.set(rate2.contents[0])
- lbldatetime_text.set(t)
- #LABELS
- #Label for current datetime of exchange rates
- lbltime = tk.Label(root, text="ExRate Datetime",font="Helvetica 10 bold", anchor='w', background='lightgrey').place(x=5,y=25)
- #Label datetime update
- lbldatetime_text = tk.StringVar()
- lbldatetime = tk.Label(root, textvariable=lbldatetime_text,font="Helvetica 10 bold", anchor='w', background='lightgrey').place(x=180,y=25)
- #Label for from textbox
- lblfrmcur = tk.Label(root, text="From Currency",font="Helvetica 10 bold", width=12, anchor='w', background='lightgrey').place(x=5,y=50)
- #Label for from currency exrate
- lblfrmex_text = tk.StringVar()
- lblfrmex = tk.Label(root, textvariable=lblfrmex_text,font="Helvetica 10 bold", anchor='w', background='lightgrey').place(x=180,y=50)
- #Labels for to textbox
- lbltocur = tk.Label(root, text="To Currency",font="Helvetica 10 bold", width=12, anchor='w', background='lightgrey').place(x=5,y=75)
- #Label for to currency exrate
- lbltoex_text = tk.StringVar()
- lbltoex = tk.Label(root, textvariable=lbltoex_text,font="Helvetica 10 bold", anchor='w', background='lightgrey').place(x=180,y=75)
- #End
- #Textboxes for user input
- cur1_1 = tk.StringVar()
- txtcur1 = tk.Entry(root, font="Helvetica 11 bold",bg="white", width=6, textvariable=cur1_1).place(x=110, y=50)
- cur2_1 = tk.StringVar()
- txtcur2 = tk.Entry(root, font="Helvetica 11 bold",bg="white", width=6, textvariable=cur2_1).place(x=110, y=75)
- #End
- #Buttons
- btnConvert = tk.Button(root, text="Get Exchange Rates",font="Helvetica 11 bold",bg="white",command=results).place(x=5,y=102)
- #End
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement