0

Currently working on a GUI using tkinter. I want to implement a pretty standard request on the coingecko API to fetch the current price of Ethereum. This works fine so far. But I want this request to happen every 60 seconds to have the most recent price displayed in the GUI at all time.

import requests
import json

def get_eth():
    eth = requests.get("https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=eur").text
    eth = json.loads(eth)
    return(eth["ethereum"]["eur"],"€")

1 Answers1

0

You can basically try this :

import requests
import json
from tkinter import Label,Tk

def get_eth():
    eth = requests.get("https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=eur").text
    eth = json.loads(eth)
    L.config(text=f'{eth["ethereum"]["eur"]}€')
    root.after(60000,get_eth)

root=Tk()

L=Label(root,text="")
L.pack()

get_eth()

root.mainloop()
imxitiz
  • 3,920
  • 3
  • 9
  • 33
  • ```root.after(get_eth,60000)```? Or ```root.after(60000,get_eth)``` –  Aug 04 '21 at 09:11
  • it is fine, right? Then, mark this as accepted answer. If it solved your problem. @FrederikSchneck :) – imxitiz Aug 04 '21 at 09:24