🗣 Wd提问: btcs app
🤖 Ai回答: Here's a Python Bitcoin price tracker app using Tkinter and the CoinGecko API:
python
import tkinter as tk
from tkinter import ttk, messagebox
import requests
import threading
class BitcoinTracker:
def __init__(self, root):
self.root = root
self.root.title(Bitcoin Price Tracker)
self.root.geometry(400x200)
self.root.resizable(False, False)
Configure styles
self.style = ttk.Style()
self.style.configure(TLabel, font=(Arial, 12))
self.style.configure(TButton, font=(Arial, 10))
Create UI elements
self.create_widgets()
Start price updates
self.update_price()
def create_widgets(self):
Header
header = ttk.Label(self.root, text=BITCOIN PRICE TRACKER, font=(Arial, 14, bold))
header.pack(pady=10)
Price display
self.price_var = tk.StringVar(value=Loading...)
price_label = ttk.Label(self.root, textvariable=self.price_var, font=(Arial, 24))
price_label.pack(pady=10)
Last updated
self.updated_var = tk.StringVar()
updated_label = ttk.Label(self.root, textvariable=self.updated_var)
updated_label.pack(pady=5)
Buttons frame
button_frame = ttk.Frame(self.root)
button_frame.pack(pady=10)
Refresh button
refresh_btn = ttk.Button(button_frame, text=Refresh, command=self.manual_refresh)
refresh_btn.pack(side=tk.LEFT, padx=5)
Quit button
quit_btn = ttk.Button(button_frame, text=Quit, command=self.root.destroy)
quit_btn.pack(side=tk.LEFT, padx=5)
def fetch_price(self):
try:
url = https://api.coingecko.com/api/v3/simple/price
params = {
ids: bitcoin,
vs_currencies: usd,
include_last_updated_at: True
}
response = requests.get(url, params=params, timeout=10)
data = response.json()
if 'bitcoin' in data:
price = data['bitcoin']['usd']
timestamp = data['bitcoin']['last_updated_at']
return price, timestamp
return None, None
except Exception as e:
print(fError fetching data: {e})
return None, None
def update_price(self):
def update():
price, timestamp = self.fetch_price()
if price is not None:
self.price_var.set(f${price:,.2f})
self.updated_var.set(fLast updated: {self.format_timestamp(timestamp)})
else:
self.price_var.set(Data unavailable)
self.updated_var.set()
Schedule next update
self.root.after(60000, self.update_price) Update every 60 seconds
Run in separate thread to prevent UI freeze
threading.Thread(target=update, daemon=True).start()
def manual_refresh(self):
self.price_var.set(Refreshing...)
self.updated_var.set()
threading.Thread(target=self.update_price, daemon=True).start()
@staticmethod
def format_timestamp(timestamp):
from datetime import datetime
dt = datetime.fromtimestamp(timestamp)
return dt.strftime(%Y-%m-%d %H:%M:%S)
if __name__ == __main__:
root = tk.Tk()
app = BitcoinTracker(root)
root.mainloop()
Features:
1、Real-time Bitcoin price display in USD
2、Auto-refresh every 60 seconds
3、Manual refresh button
4、Last updated timestamp
5、Clean, responsive UI
6、Error handling for network issues
Requirements:
Python 3.x
Install required packages: `pip install requests`
How to Use:
1、Save the code as `bitcoin_tracker.py`
2、Run the script: `python bitcoin_tracker.py`
3、The app will show:
Current Bitcoin price in USD
Last update time
Refresh button for manual updates
Quit button to exit
Notes:
Uses CoinGecko's free API (no API key needed)
Updates automatically every minute
Network errors will show Data unavailable
The UI remains responsive during updates

For a more advanced version, you could add:
1、Price change indicators (24h change)
2、Multiple cryptocurrency support
3、Price history charts
4、Currency conversion options
5、Desktop notifications for price alerts
Would you like me to explain any specific part of the code or add additional features?
0
IP地址: 110.58.216.142
搜索次数: 0
提问时间: 2025-09-08 21:40:35
❓ 热门提问:
steam下载速度慢
ebay可以用吗
纸飞机简笔画涂色
推特英文发音是什么
网络加速器的原理图
steam是什么意思?
推特用语 英文
steam是什么课程
推特博主是我弟by猫女
加速器如何给网页加速
📢 温馨提示:本站所有问答由Ai自动创作,内容仅供参考,若有误差请用“联系”里面信息通知我们人工修改或删除。
👉 技术支持:本站由JJ加速器提供技术支持,使用的最新版:《JJ加速器Ai问答系统 V.25.09.02》搭建本站。