繁体   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