mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-27 14:01:09 +00:00
Merge pull request #24 from amirulabu/Bitcoin-Price-GUI
Bitcoin price gui
This commit is contained in:
commit
031004e5c8
3
Bitcoin-Price-GUI/README.md
Normal file
3
Bitcoin-Price-GUI/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Bitcoin price GUI
|
||||
|
||||
Tells the current price of bitcoin using Python's TKinter library
|
35
Bitcoin-Price-GUI/bitcoin-price.py
Normal file
35
Bitcoin-Price-GUI/bitcoin-price.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
import urllib.request
|
||||
import json
|
||||
import time
|
||||
|
||||
def get_luno():
|
||||
# to change ticker pair, look at here https://api.mybitx.com/api/1/tickers
|
||||
req = urllib.request.urlopen("https://api.mybitx.com/api/1/ticker?pair=XBTMYR")
|
||||
x = json.loads(req.read().decode("utf-8"))
|
||||
req.close()
|
||||
return x
|
||||
|
||||
def refresh_price():
|
||||
aLable.configure(text="Ask price: RM " + get_luno()["ask"])
|
||||
bLable.configure(text="Time: " +
|
||||
str(time.strftime("%Y-%m-%d %H:%M:%S",
|
||||
time.gmtime(get_luno()["timestamp"]/1000 + 28800))))
|
||||
|
||||
win = tk.Tk()
|
||||
win.title("Bitcoin price in MYR")
|
||||
|
||||
aLable = ttk.Label(win, text="Ask price: RM " + get_luno()["ask"])
|
||||
aLable.grid(column=0, row=0, padx=8, pady=4)
|
||||
|
||||
bLable = ttk.Label(text="Time: " +
|
||||
str(time.strftime("%Y-%m-%d %H:%M:%S",
|
||||
time.gmtime(get_luno()["timestamp"]/1000 + 28800))))
|
||||
bLable.grid(column=0, row=1, padx=8, pady=4)
|
||||
|
||||
action = ttk.Button(win, text="Refresh", command=refresh_price)
|
||||
action.grid(column=0, row=2, padx=8, pady=4)
|
||||
|
||||
win.mainloop()
|
||||
|
Loading…
Reference in New Issue
Block a user