-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbitcoin.py
More file actions
64 lines (52 loc) · 1.6 KB
/
Copy pathbitcoin.py
File metadata and controls
64 lines (52 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from tkinter import *
from PIL import Image, ImageTk
from bs4 import BeautifulSoup
from urllib.request import Request, urlopen
import re
from datetime import datetime
import webbrowser
URL = "https://kr.investing.com/crypto/bitcoin/"
hdr = {'User-Agent': 'Mozilla/5.0'}
root = Tk()
root.title("비트코인 시세 조회")
root.geometry("500x200")
root.option_add("*Font", "맑은고딕 20")
root.config(bg="black")
# Frame 생성
my_frame = Frame(root)
my_frame.pack(pady=20)
#비트코인 logo 표시
img = ImageTk.PhotoImage(Image.open('bitcoin.png').resize((100, 100)))
logo_label = Label(my_frame, image=img)
logo_label.grid(row=0, column=0)
#비트코인 가격 표시
bit_label = Label(my_frame)
bit_label.grid(row=0, column=1)
status = Label(root)
status.pack()
def update():
#비트코인 site 접속
req = Request(URL, headers=hdr)
page = urlopen(req)
#웹페이지 파싱
html = BeautifulSoup(page, "html.parser")
found = html.find(class_="newInput inputTextBox alertValue")
found = re.search("[0-9,.]+", str(found))
price = found.group()
#가격 표시
bit_label.config(text=price)
# 현재 시간 표시
now = datetime.now()
current_time = now.strftime("%I:%M:%S %p")
status.config(text=f"최근 갱신 - {current_time}")
#timer 를 5 초로 setting
root.after(5000, update)
# program start 시 update 함수 수행
update()
#website 직접 연결 button 생성
def callback():
webbrowser.open_new(URL)
btn = Button(my_frame, text="웹사이트 바로가기")
btn.config(command=callback)
btn.grid(row=0, column=2)
root.mainloop()