Jan-10-2018, 10:03 AM
Hi i'm working on improving my code and making it clearer/shorter.
I'm having problems using the function i created. I can use this in Idle on the command line i.e Price(ripple) but not within the script.
Any ideas or a nudge in the right direction.
Look forward to any replies.
regards
J
I'm having problems using the function i created. I can use this in Idle on the command line i.e Price(ripple) but not within the script.
Any ideas or a nudge in the right direction.
Look forward to any replies.
regards
J
from tkinter import * import requests import json crypto = {'ripple': '10', 'iota': '20'} # dictionary of crypto name and units pruchased class Crypto: def __init__(self, coin, price): url = 'https://api.coinmarketcap.com/v1/ticker/' self.coin = coin self.price = price self.api = url + coin def Price(self): #at command window type: Price(ripple) json_data = requests.get(self.api).json() dic = json.dumps(json_data) dict = json.loads(dic)[0] #print (dict) print (float(dict['price_usd'])) #price = ("%.2f" %(dict['price_usd'])) #pricefloat = str(round(price,2)) #print = (pricefloat) def URL(self): #at command window type: URL(ripple) print (self.api) #rippleprice = Price(ripple) # this does not work m=0 r=0 s=0 for key in crypto.keys(): Label(text=key, relief=RIDGE, width=15).grid(row=r, column=0) r =r+1 for values in crypto.values(): Label(text = values, relief=RIDGE, width=15).grid(row=m, column=1) m = m + 1 #Label(text = Price(ripple), relief=RIDGE, width=15).grid(row=0, column=2) # this does not work mainloop()