Previously the cryptocurrency application has loaded the world currency text file and then populate the currency combo box based on the currency symbol in that text file. In this article, the cryptocurrency program will use the returning currency symbol from Blockchain to populate that same combo box.
Populate the currency combo box with currency symbols from Blockchain.
for k in ticker: #sell_buy += "BTC:" + str(k) + " " + str(ticker[k].p15min) + "\n" currency_exchange_rate.append((ticker[k].p15min)) currency_index.append(str(k)) curr1 += (str(k),) # the tuple used to populate the currency combo box
As you can see all the currency symbols will be kept in a tuple which will then be used to populate the currency combo box.
Below is the entire code used to populate the combo box with the currency symbol.
def get_exchange_rate(): # this method will display the incoming exchange rate data after the api called global exchange_rate global base_crypto # read the currency file #c_string = '' #with open('currency.txt') as fp: #for currency in fp.readlines(): #c_string += currency[:-1] + "," #c_string = c_string[:-1] #base_crypto = crypto.get() # get the desired crypto currency #try: #url = "https://min-api.cryptocompare.com/data/price" # url for API call #data = {'fsym': base_crypto, 'tsyms': c_string} # = requests.get(url, params=data) #exchange_rate_s = json.loads(json.dumps(r.json())) #except: #print("An exception occurred") curr1 = tuple() # the tuple which will be populated by currency sell_buy = '' #for key, value in exchange_rate_s.items(): # populate exchange rate string and the currency tuple #sell_buy += base_crypto + ":" + key + " " + str(value) + "\n" #curr1 += (key,) #sell_buy += "Bitcoin : Currency price every 15 minute:" + "\n\n" # print the 15 min price for every bitcoin/currency currency_exchange_rate = [] currency_index = [] for k in ticker: #sell_buy += "BTC:" + str(k) + " " + str(ticker[k].p15min) + "\n" currency_exchange_rate.append((ticker[k].p15min)) currency_index.append(str(k)) curr1 += (str(k),) # the tuple used to populate the currency combo box # construct the pandas data frame object d = {'BTC': currency_exchange_rate} df = pd.DataFrame(data=d, index=currency_index) countVar = StringVar() # use to hold the character count text_widget.tag_remove("search", "1.0", "end") # cleared the hightlighted currency pair text_widget.delete('1.0', END) # clear all those previous text first s.set(df) text_widget.insert(INSERT, s.get()) # populate the text widget with new exchange rate data # highlight the background of the searched currency pair pos = text_widget.search('AUD', "1.0", stopindex="end", count=countVar) text_widget.tag_configure("search", background="green") end_pos = float(pos) + float(0.96) text_widget.tag_add("search", pos, str(end_pos)) pos = float(pos) + 2.0 text_widget.see(str(pos)) # fill up combo box of world currency based['values'] = curr1 based.current(0) # enable all buttons action_search.config(state=NORMAL) action_coin_volume.config(state=NORMAL) action_coin_market_cap.config(state=NORMAL) action_coin_top_exchange.config(state=NORMAL)
Some of the code has appeared in the previous chapter which you can read them in the previous article.
from Planet Python
via read more
No comments:
Post a Comment