티스토리 뷰
주식 투자에서 3%를 기준으로 단타를 때리는 '놀이'를 하고 있다. 이건 버튼 누르기 놀이일 수 밖에 없는게 타이밍/ 종목 잘못타면 3%고 뭐고 파사삭~ 날라가기 때문이다. 그러니까 주요 투자는 잘 박아두고, 날아가도 술 한잔 거하게 한 셈치면 될 투기용 머니(?)가지고 난 이 게임을 한다.
타이밍이 중요한 이 게임을 위해 파이선으로 계산기를 만들었다. 초간단하게 가격 넣으면 3% 위 아래로 계산해주는 윈도우 앱.
코드는 따로짤 것도 없이 제미나이에게 이렇게 해줘~ 하니 짜줬다.
import tkinter as tk
from tkinter import ttk # For modern widgets
def calculate_prices():
try:
current_price = float(entry_price.get())
if current_price <= 0:
raise ValueError("Price must be a positive number.")
increase_price = current_price * 1.03 # 3% increase
decrease_price = current_price * 0.97 # 3% decrease
label_increase.config(text=f"3% Higher: {increase_price:.2f}")
label_decrease.config(text=f"3% Lower: {decrease_price:.2f}")
except ValueError as e:
label_increase.config(text=f"Error: {e}") # Display error message
label_decrease.config(text="") # Clear the other label
# Create the main window
window = tk.Tk()
window.title("Stock Price Calculator")
# Price Input
label_current = ttk.Label(window, text="Current Price:") # Use ttk Label
label_current.grid(row=0, column=0, padx=5, pady=5, sticky="w") # Sticky aligns to west
entry_price = ttk.Entry(window) # Use ttk Entry
entry_price.grid(row=0, column=1, padx=5, pady=5)
# Calculate Button
button_calculate = ttk.Button(window, text="Calculate", command=calculate_prices) # Use ttk Button
button_calculate.grid(row=1, column=0, columnspan=2, pady=(10, 5)) # Span across columns
# Output Labels
label_increase = ttk.Label(window, text="3% Higher:") # Use ttk Label
label_increase.grid(row=2, column=0, columnspan=2, padx=5, pady=(5,0), sticky="w")
label_decrease = ttk.Label(window, text="3% Lower:") # Use ttk Label
label_decrease.grid(row=3, column=0, columnspan=2, padx=5, pady=(0,5), sticky="w")
window.mainloop()
|
비주얼 스튜디오 코드에 오려붙여 넣고 가지고 노는 중이다. 뭐... 더 더해볼까? 주식 티커로 현재 가격을 읽어와서 자동으로 계산해주는 앱?
'누리모' 카테고리의 다른 글
애플 노트를 윈도에서 앱처럼 사용하기 (0) | 2025.02.19 |
---|---|
크롬 테마, 단순함과 변별력을 더하다 (0) | 2019.08.05 |
글꼴, 사용권 제한 없는 한글 글꼴 안전하게 받기 (0) | 2019.02.11 |
글꼴, TTF와 OTF 중에 무엇을 설치할까? (0) | 2019.02.10 |
코드를 깔끔하게 보관하고 싶다면, 부스트노트 (0) | 2019.02.06 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 게임
- 한글
- 불여우
- 방화벽
- Korean
- 맥
- 애플
- 무른모
- 동영상
- 글꼴
- 아이패드
- firefox
- Ubuntu Linux
- 아이폰4
- 데스크탑
- 우분투 리눅스
- 설치
- 판올림
- 꾸미기
- 아이폰
- 우분투
- compiz-fusion
- 폰트
- 터미널
- 7.10
- 설명서
- 아이맥
- 8.10
- 프로그램들
- 8.04
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함