簡體   English   中英

實時更新 tkinter gui

[英]Make the tkinter gui update live

我正在制作比特幣價格 GUI。 我想知道,有什么方法可以實時更新價格?

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()

您可以使用.after()方法。

def Update(
     ... code that gets prices and updates screen)
     root.after(1000, Update)

這將每 1000 毫秒(1 秒)更新一次屏幕



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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM