1

How can I use Tk.after to continuously update a tkinter display asynchronously in Jupyter Notebook?

I found this link that explains something similar Using async/await keywords with Tk.after() method of tkinter, but this won't work on Jupyter, since Jupyter already has a running loop.

The idea is to update the BTC bid/ask price and volume on a tkinter page every 2 seconds

The following code is the code that I have written, which currently rturns the following error: object function can't be used in 'await' expression

from bfxapi import Client
from tkinter import *

# initialize client
bfx = Client(
  API_KEY=API_KEY,
  API_SECRET=API_SECRET,
  logLevel='DEBUG'
)

root = Tk()

async def GUI():
    ticker = await bfx.rest.get_public_ticker(symbol) # get ticker info from bitfinex api
    # ro 0 --> Title
    Label(root, text='Ticker').grid(row=0,column=0)
    Label(root, text='Bid').grid(row=0,column=1)
    Label(root, text='Ask').grid(row=0,column=2)
    Label(root, text='Volume').grid(row=0,column=3)
    # row 1 --> Info
    Label(root, text='BTCUSD').grid(row=1,column=0) # BTCUSD ticker
    Label(root, text=ticker[0]).grid(row=1,column=1) # bid price from bfx
    Label(root, text=ticker[2]).grid(row=1,column=2) # ask price from bfx
    Label(root, text=ticker[7]).grid(row=1,column=3) # volume from bfx
    # loop
    root.after(2000, await GUI) # run itself again after 2000 ms

# run first time
await GUI()
#run the tkinter loop
root.mainloop()
nijasio
  • 11
  • 3

0 Answers0