I'm making a Bitcoin price GUI. And I was wondering, is there any way to make the price update live?
page = urllib.request.urlopen("https://www.coindesk.com/price/bitcoin").read()
html = BeautifulSoup(page, "html.parser")
btcClass = html.find(class_="price-large")
btcClass1 = str(f"{btcClass}$")
btcClass2 = btcClass1[54:63]
Label1 = tkinter.Label(text=f"BTC\n{btcClass2}", font=("Arial", 25)).pack()
def Update():
#price update
Update()
You could use the .after()
method.
def Update(
... code that gets prices and updates screen)
root.after(1000, Update)
this will update your screen every 1000ms (1 second)
Update():
html = BeautifulSoup(page, "html.parser")
btcClass = html.find(class_="price-large")
btcClass1 = str(f"{btcClass}$")
btcClass2 = btcClass1[54:63]
label.config(text=f"BTC\n{btcClass2}"
root.after(1000, Update)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.