반응형

파이썬

(파이썬) tkinter: 화씨 섭씨 온도 변환하기

tkinter 윈도우 GUI 프로그램으로 화씨온도를 섭씨온도로 변환하기 tkinter 윈도우 GUI 프로그램으로 섭씨온도를 화씨온도로 변환하기 참고로, 화씨 100 °F는 섭씨 37.8 °C이고 반대로 계산해도 같은 값이 나와야 합니다. 인터넷 상에 변환하는 코드는 많은데 막상 실행해 보면 답이 틀린게 많이 있습니다. from tkinter import * def f2c(): f = float(e1.get()) c = (f-32)*5/9 e2.delete(0, END) e2.insert(0, str(c)) def c2f(): c = float(e2.get()) f = (c*(9/5))+32 e1.delete(0, END) e1.insert(0, str(f)) win = Tk() win.title('화씨/..

Python 2024.01.11

(파이썬) 터틀그래픽: 눈사람 그리기

파이썬 터틀 그래픽으로 눈사람을 그리는 코드입니다. import turtle t = turtle.Turtle() t.shape("turtle") t.color("black", "white") s = turtle.Screen(); s.bgcolor('skyblue'); def snowman(x, y): t.up() t.goto(x, y) t.down() t.begin_fill() t.circle(20) t.end_fill() t.goto(x, y-25) t.setheading(135) t.forward(50) t.backward(50) t.setheading(30) t.forward(50) t.backward(50) t.setheading(0) t.goto(x, y-70) t.begin_fill() t.c..

Python 2024.01.10

(파이썬) 파이썬 게임: 스페이스 인베이더 Space Invaders

이 코드는 Pygame을 사용하여 간단한 2D 게임을 만드는 예제입니다. 코드를 실행하면 창이 열리고 키보드의 좌우 키로 플레이어를 움직일 수 있습니다. 적이 화면 위에서 아래로 내려오면서 플레이어와 충돌하면 게임이 종료됩니다. 이 프로그램을 실행하기 위해서는 "pygame" 모듈이 설치되어 있어야 합니다. pip install pygame import pygame import random # 초기화 pygame.init() # 화면 크기 설정 screen_width = 600 screen_height = 400 screen = pygame.display.set_mode((screen_width, screen_height)) pygame.display.set_caption("Space Invaders")..

Python 2024.01.01
반응형