개발자/라즈베리파이4

시계가 없어서 10분 만에 만든 디지털 시계 2. 라즈베리파이 사용.

지구빵집 2021. 2. 16. 10:34
반응형

 

 

Python 및 Tkinter로 시계를 만드는 방법. 고정 IP 설정도 해야 함.

 

알람, 스톱워치, 타이머를 지원하는 디지털시계를 만들 것입니다. 라즈베리파이의 리눅스 환경에서 환경에서 Python 3을 사용합니다. 실행하실 때 GUI 화면으로 부팅해야 합니다. 터미널 화면으로 부팅하셨다면 아래 명령으로 윈도우를 실행하세요. 터미널에서 실행하면 뜨는 에러를 설명해 두었으니 참고하세요. 혹시 궁금하신 게 있으면 댓글에 적어주세요.~라고 해도 안 적어요. ^^

 

잠깐 여기서 라즈베리파이 고정 IP 설정을 해야 항상 시간을 제대로 설정한다. 다음 파일을 연다.

 

$sudo nano /etc/network/interfaces

열어서 다음과 같은 설정을 자신의 네트워크 환경에 맞게 설정한다.

 

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet static
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    address 192.168.168.111
    netmask 255.255.255.0
    gateway 192.168.168.1
    network 192.168.168.0
    broadcast 192.168.168.255

다음으로 할 일이 공유기를 접속해 무선이든 유선이든 주소를 받아오도록 설정하는 일이다.

 

아래 명령으로 파일을 열고 자신의 네트워크에 맞는 공유기 환경을 설정하도록 한다.

 

$sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

 

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US

network={
        ssid="PISnet_032AC8"
        psk="82988298"
        key_mgmt=WPA-PSK
}

network={
        ssid="CARELAB"
        psk="82988298"
        key_mgmt=WPA-PSK
}

 

인터넷 공유기 설정을 완료하였다면 아래를 진행한다.

 

$startx

 

알람 및 타이머에서 시간이 다되었을 때 경고음을 냅니다. 이 Beep은 Windows의 'winsound.Beep ()'및 Unix의 'Beep'CLI에 의해 생성됩니다. 아래는 디지털시계를 구현한 데모 이미지입니다. 소리는 아직 확인하지 않았습니다. 필요한 것은 디지털시계이기 때문입니다. 

 

A digital Clock

 

먼저 'digital_clock.py'라는 파일을 생성하고 nano 편집기에서 엽니다. 라즈베리파이에서 putty를 통해 연결하고 ssh 환경과 편집기를 사용하는 방법에 대해 참고하십시요. 

 

우선 모듈을 import 합니다. 아래와 같은 모듈을 가져옵니다. 

 

from tkinter import *
from tkinter.ttk import *
import datetime
import platform
try:
        import winsound #windows
except:
        import os #other

 

여기에서는 Tkinter, datetime, platform (Beep용 운영 체제 결정용), winsound (Windows 전용), os (Unix 전용)를 가져왔습니다.

 

from tkinter import *
from tkinter.ttk import *
import datetime
import platform
try:
        import winsound #windows
except:
        import os #other

 

Tkinter 창 만들기. 이제 tkinter 창을 만들 것입니다. 

 

window = Tk()
window.title("Clock")
window.geometry('500x250')

 

여기에 간단한 Tkinter 창을 만들었습니다. 우리는 제목을 “시계”로 선언했습니다. 크기를 '500X250'으로 설정합니다.

 

Tkinter 탭 컨트롤 추가

 

탭 컨트롤을 추가하려면 Tkinter 노트북을 사용할 수 있습니다. 여기에 시계, 알람, 스톱워치, 타이머에 대해 각각 4 개의 탭을 추가합니다. 

 

tabs_control = Notebook(window)
clock_tab = Frame(tabs_control)
alarm_tab = Frame(tabs_control)
stopwatch_tab = Frame(tabs_control)
timer_tab = Frame(tabs_control)
tabs_control.add(clock_tab, text="Clock")
tabs_control.add(alarm_tab, text="Alarm")
tabs_control.add(stopwatch_tab, text='Stopwatch')
tabs_control.add(timer_tab, text='Timer')
tabs_control.pack(expand = 1, fill ="both")

 

각 탭에 프레임을 사용한 다음 노트북에 추가했습니다.

 

시계 만들기

 

이제 디지털시계를 만듭니다.

 

Clock Tkinter 구성 요소 추가

 

이제 시계 용 tkinter 구성 요소를 추가합니다.  

 

time_label = Label(clock_tab, font = 'calibri 40 bold', foreground = 'black')
time_label.pack(anchor='center')
date_label = Label(clock_tab, font = 'calibri 40 bold', foreground = 'black')
date_label.pack(anchor='s')

 

여기에 두 개의 레이블, 시간 및 날짜를 ​​추가했습니다. 둘 다 기능 시계에서 데이터를 가져옵니다.

 

시계 기능 만들기

 

이제 시간 및 날짜 레이블을 제어하는 ​​시계 기능을 만들 것입니다. 

 

def clock():
        date_time = datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S/%p")
        date,time1 = date_time.split()
        time2,time3 = time1.split('/')
        hour,minutes,seconds =  time2.split(':')
        if int(hour) > 12 and int(hour) < 24:
                time = str(int(hour) - 12) + ':' + minutes + ':' + seconds + ' ' + time3
        else:
                time = time2 + ' ' + time3
        time_label.config(text = time)
        date_label.config(text= date)
        time_label.after(1000, clock)

 

이 함수에서는 datetime 모듈에서 날짜와 시간을 가져와서 PM과 AM Time으로 변환합니다. 이 함수는 Tkinter 초기화 아래와 노트북 초기화 위에 추가해야 합니다.

 

알람 생성

 

이제 시간이 다되면 신호음을 울리는 A Alarm을 생성합니다.

 

알람 Tkinter 구성 요소 추가. 

 

get_alarm_time_entry = Entry(alarm_tab, font = 'calibri 15 bold')
get_alarm_time_entry.pack(anchor='center')
alarm_instructions_label = Label(alarm_tab, font = 'calibri 10 bold', text = "Enter Alarm Time. Eg -> 01:30 PM, 01 -> Hour, 30 -> Minutes")
alarm_instructions_label.pack(anchor='s')
set_alarm_button = Button(alarm_tab, text = "Set Alarm", command=alarm)
set_alarm_button.pack(anchor='s')
alarm_status_label = Label(alarm_tab, font = 'calibri 15 bold')
alarm_status_label.pack(anchor='s')

 

 

여기에 이 형식 → HH : MM (PM / AM)으로 알람을 설정하도록 알려주는 Get Alarm Entry Box, Alarm Instructions가 추가되었습니다. 예를 들어 01:30 PM은 13:30 시간을 의미합니다. 그러면 알람 기능을 호출하는 알람 설정 버튼입니다. 그리고 알람 상태 레이블은 알람에 대해 표시하고, 알람이 설정되었는지 여부, 그리고 시간이 끝났습니다.

 

알람 기능 만들기

 

여기서는 set_alarm_button에 의해 호출되는 알람 함수를 만들 것입니다. 이 기능을 노트북 초기화 위와 시계 기능 아래에 추가하십시오. 

 

def alarm():
        main_time = datetime.datetime.now().strftime("%H:%M %p")
        alarm_time = get_alarm_time_entry.get()
        alarm_time1,alarm_time2 = alarm_time.split(' ')
        alarm_hour, alarm_minutes = alarm_time1.split(':')
        main_time1,main_time2 = main_time.split(' ')
        main_hour1, main_minutes = main_time1.split(':')
        if int(main_hour1) > 12 and int(main_hour1) < 24:
                main_hour = str(int(main_hour1) - 12)
        else:
                main_hour = main_hour1
        if int(alarm_hour) == int(main_hour) and int(alarm_minutes) == int(main_minutes) and main_time2 == alarm_time2:
                for i in range(3):
                        alarm_status_label.config(text='Time Is Up')
                        if platform.system() == 'Windows':
                                winsound.Beep(5000,1000)
                        elif platform.system() == 'Darwin':
                                os.system('say Time is Up')
                        elif platform.system() == 'Linux':
                                os.system('beep -f 5000')
                get_alarm_time_entry.config(state='enabled')
                set_alarm_button.config(state='enabled')
                get_alarm_time_entry.delete(0,END)
                alarm_status_label.config(text = '')
        else:
                alarm_status_label.config(text='Alarm Has Started')
                get_alarm_time_entry.config(state='disabled')
                set_alarm_button.config(state='disabled')
        alarm_status_label.after(1000, alarm)

 

Here It 시간 형식 datetime 모듈을 가져와서 형식을 지정합니다. 입력 한 시간이 같은지 확인합니다. 동일한 경우 운영 체제에 따라 경고음이 울립니다.

 

스톱워치 만들기

 

이제 프로그램에서 스톱워치를 만들 것입니다. 스톱워치 Tkinter 구성 요소 추가 이제 스톱워치의 tkinter 구성 요소를 추가합니다. 

 

stopwatch_label = Label(stopwatch_tab, font='calibri 40 bold', text='Stopwatch')
stopwatch_label.pack(anchor='center')
stopwatch_start = Button(stopwatch_tab, text='Start', command=lambda:stopwatch('start'))
stopwatch_start.pack(anchor='center')
stopwatch_stop = Button(stopwatch_tab, text='Stop', state='disabled',command=lambda:stopwatch('stop'))
stopwatch_stop.pack(anchor='center')
stopwatch_reset = Button(stopwatch_tab, text='Reset', state='disabled', command=lambda:stopwatch('reset'))
stopwatch_reset.pack(anchor='center')

 

여기에는 스톱워치 기능을 호출하는 스톱워치 레이블, 시작, 중지, 재설정 버튼이 있습니다.

 

스톱워치 카운터 기능 추가

 

이제 스톱워치를 작동하는 스톱워치 카운터 기능을 추가합니다. 먼저 두 줄의 스톱워치 카운터를 추가합니다. 아래 Tkinter 초기화 및 클록 기능 위에 추가하십시오. 

 

stopwatch_counter_num = 66600
stopwatch_running = False

 

이 선은 스톱워치에 대해 알려줍니다. 이제 스톱워치 카운터 기능을 추가합니다. 알람 기능 아래와 노트북 초기화 위에 추가합니다. 

 

def stopwatch_counter(label):
        def count():
                if stopwatch_running:
                        global stopwatch_counter_num
                        if stopwatch_counter_num==66600:
                                display="Starting..."
                        else:
                                tt = datetime.datetime.fromtimestamp(stopwatch_counter_num) 
                                string = tt.strftime("%H:%M:%S") 
                                display=string 
                        label.config(text=display)
                        label.after(1000, count)
                        stopwatch_counter_num += 1
        count()

 

스톱워치를 작동시키는 스톱워치 카운터입니다. 1 초마다 스톱워치 카운터 번호에 1을 추가합니다.

 

스톱워치 기능 추가

 

이제 스톱워치를 제어하고 스톱워치 버튼에 의해 호출되는 스톱워치 기능을 추가합니다. 

 

def stopwatch(work):
         if work == 'start':
                 global stopwatch_running
                 stopwatch_running=True
                 stopwatch_start.config(state='disabled')
                 stopwatch_stop.config(state='enabled')
                 stopwatch_reset.config(state='enabled')
                 stopwatch_counter(stopwatch_label)
         elif work == 'stop':
                 stopwatch_running=False
                 stopwatch_start.config(state='enabled')
                 stopwatch_stop.config(state='disabled')
                 stopwatch_reset.config(state='enabled')
         elif work == 'reset':
                 global stopwatch_counter_num
                 stopwatch_running=False
                 stopwatch_counter_num=66600
                 stopwatch_label.config(text='Stopwatch')
                 stopwatch_start.config(state='enabled')
                 stopwatch_stop.config(state='disabled')
                 stopwatch_reset.config(state='disabled')

 

이 기능에서 작업이 시작되면 → 스톱워치 카운터를 호출하고 Stopwatch running을 'True'로 설정합니다. Stop 일 경우 → 스톱워치 실행을 'False'로 설정합니다. Reset 인 경우 → Counter num을 66600 또는 0으로 설정하고 'False'로 실행

 

타이머 만들기

 

이제 시간이 다되면 신호음이 울리는 타이머를 만들 것입니다. 그것은 스톱워치의 원리로 작동하지만 카운터에 1을 추가하는 대신 1을 뺍니다.

 

타이머 Tkinter 구성 요소 추가

 

이제 타이머의 tkinter 구성 요소를 추가합니다. 

 

timer_get_entry = Entry(timer_tab, font='calibiri 15 bold')
timer_get_entry.pack(anchor='center')
timer_instructions_label = Label(timer_tab, font = 'calibri 10 bold', text = "Enter Timer Time. Eg -> 01:30:30, 01 -> Hour, 30 -> Minutes, 30 -> Seconds")
timer_instructions_label.pack(anchor='s')
timer_label = Label(timer_tab, font='calibri 40 bold', text='Timer')
timer_label.pack(anchor='center')
timer_start = Button(timer_tab, text='Start', command=lambda:timer('start'))
timer_start.pack(anchor='center')
timer_stop = Button(timer_tab, text='Stop', state='disabled',command=lambda:timer('stop'))
timer_stop.pack(anchor='center')
timer_reset = Button(timer_tab, text='Reset', state='disabled', command=lambda:timer('reset'))
timer_reset.pack(anchor='center')

 

여기에는 get Timer 항목이 있습니다. 이 형식으로 타이머를 설정해야 한다는 지침 → HH : MM : SS 예 → 01:30:40은 1 시간 30 분 40 초를 의미합니다. Timer 기능을 호출하는 Start, Stop, Reset 버튼이 있습니다.

 

타이머 카운터 기능 추가

 

이제 타이머를 작동시키는 타이머 카운터 기능을 추가하겠습니다. 먼저 두 줄의 타이머 카운터를 추가합니다. 아래 스톱워치의 두 줄 및 시계 기능 위에 추가하십시오. 

 

timer_counter_num = 66600
timer_running = False

 

이 줄은 타이머에 대해 알려줍니다. 이제 타이머 카운터 기능을 추가하겠습니다. 스톱워치 기능 아래 및 노트북 초기화 위에 추가하십시오. 

 

def timer_counter(label):
        def count():
                global timer_running
                if timer_running:
                        global timer_counter_num
                        if timer_counter_num==66600:
                            for i in range(3):
                                    display="Time Is Up"
                                    if platform.system() == 'Windows':
                                        winsound.Beep(5000,1000)
                                    elif platform.system() == 'Darwin':
                                        os.system('say Time is Up')
                                    elif platform.system() == 'Linux':
                                        os.system('beep -f 5000')
                            timer_running=False
                            timer('reset')
                        else:
                                tt = datetime.datetime.fromtimestamp(timer_counter_num) 
                                string = tt.strftime("%H:%M:%S") 
                                display=string
                                timer_counter_num -= 1
                        label.config(text=display)
                        label.after(1000, count)
        count()

 

Timer를 동작시키는 Timer 카운터입니다. 1 초마다 Timer counter num에서 1을 뺍니다.

 

타이머 기능 추가

 

이제 Timer를 제어하고 Timer Buttons에 의해 호출되는 Timer 함수를 추가합니다. 

 

def timer(work):
         if work == 'start':
                 global timer_running, timer_counter_num
                 timer_running=True
                 if timer_counter_num == 66600:
                         timer_time_str = timer_get_entry.get()
                         hours,minutes,seconds=timer_time_str.split(':')
                         minutes = int(minutes)  + (int(hours) * 60)
                         seconds = int(seconds) + (minutes * 60)
                         timer_counter_num = timer_counter_num + seconds  
                 timer_counter(timer_label)
                 timer_start.config(state='disabled')
                 timer_stop.config(state='enabled')
                 timer_reset.config(state='enabled')
                 timer_get_entry.delete(0,END)
         elif work == 'stop':
                 timer_running=False
                 timer_start.config(state='enabled')
                 timer_stop.config(state='disabled')
                 timer_reset.config(state='enabled')
         elif work == 'reset':
                 timer_running=False
                 timer_counter_num=66600
                 timer_start.config(state='enabled')
                 timer_stop.config(state='disabled')
                 timer_reset.config(state='disabled')
                 timer_get_entry.config(state='enabled')
                 timer_label.config(text = 'Timer')

 

이 기능에서 작업이 시작되면 → Timer 입력 텍스트를 가져와서 서식을 지정한 다음 서식이 지정된 텍스트로 Timer 카운터를 설정하고 Timer counter를 호출하고 Timer running을 'True'로 설정합니다. Stop 일 경우 → 동작중인 타이머를 'False'로 설정합니다. Reset 인 경우 → Counter num을 66600 또는 0으로 설정하고 'False'로 실행

 

시계 및 Tkinter 시작

 

이제 마지막 부분. 시계와 tkinter 창을 시작합니다. 끝에이 코드를 추가하십시오. 

 


clock()
window.mainloop()

 

시계 및 Tkinter 창을 시작합니다.

 

전체 소스 코드 다음은 전체 코드입니다. digital_clock.py란 이름으로 파이선 코드를 작성합니다.

 

from tkinter import *
from tkinter.ttk import *
import datetime
import platform
try:
        import winsound
        type='windows'
except:
        import os
        type='other'
import math
window = Tk()
window.title("Clock")
window.geometry('500x250')
stopwatch_counter_num = 66600
stopwatch_running = False
timer_counter_num = 66600
timer_running = False
def clock():
        date_time = datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S/%p")
        date,time1 = date_time.split()
        time2,time3 = time1.split('/')
        hour,minutes,seconds =  time2.split(':')
        if int(hour) > 12 and int(hour) < 24:
                time = str(int(hour) - 12) + ':' + minutes + ':' + seconds + ' ' + time3
        else:
                time = time2 + ' ' + time3
        time_label.config(text = time)
        date_label.config(text= date)
        time_label.after(1000, clock)
def alarm():
        main_time = datetime.datetime.now().strftime("%H:%M %p")
        alarm_time = get_alarm_time_entry.get()
        alarm_time1,alarm_time2 = alarm_time.split(' ')
        alarm_hour, alarm_minutes = alarm_time1.split(':')
        main_time1,main_time2 = main_time.split(' ')
        main_hour1, main_minutes = main_time1.split(':')
        if int(main_hour1) > 12 and int(main_hour1) < 24:
                main_hour = str(int(main_hour1) - 12)
        else:
                main_hour = main_hour1
        if int(alarm_hour) == int(main_hour) and int(alarm_minutes) == int(main_minutes) and main_time2 == alarm_time2:
                for i in range(3):
                        alarm_status_label.config(text='Time Is Up')
                        if platform.system() == 'Windows':
                                winsound.Beep(5000,1000)
                        elif platform.system() == 'Darwin':
                                os.system('say Time is Up')
                        elif platform.system() == 'Linux':
                                os.system('beep -f 5000')
                get_alarm_time_entry.config(state='enabled')
                set_alarm_button.config(state='enabled')
                get_alarm_time_entry.delete(0,END)
                alarm_status_label.config(text = '')
        else:
                alarm_status_label.config(text='Alarm Has Started')
                get_alarm_time_entry.config(state='disabled')
                set_alarm_button.config(state='disabled')
        alarm_status_label.after(1000, alarm)
def stopwatch_counter(label):
        def count():
                if stopwatch_running:
                        global stopwatch_counter_num
                        if stopwatch_counter_num==66600:
                                display="Starting..."
                        else:
                                tt = datetime.datetime.fromtimestamp(stopwatch_counter_num) 
                                string = tt.strftime("%H:%M:%S") 
                                display=string 
                        label.config(text=display)
                        label.after(1000, count)
                        stopwatch_counter_num += 1
        count()
def stopwatch(work):
         if work == 'start':
                 global stopwatch_running
                 stopwatch_running=True
                 stopwatch_start.config(state='disabled')
                 stopwatch_stop.config(state='enabled')
                 stopwatch_reset.config(state='enabled')
                 stopwatch_counter(stopwatch_label)
         elif work == 'stop':
                 stopwatch_running=False
                 stopwatch_start.config(state='enabled')
                 stopwatch_stop.config(state='disabled')
                 stopwatch_reset.config(state='enabled')
         elif work == 'reset':
                 global stopwatch_counter_num
                 stopwatch_running=False
                 stopwatch_counter_num=66600
                 stopwatch_label.config(text='Stopwatch')
                 stopwatch_start.config(state='enabled')
                 stopwatch_stop.config(state='disabled')
                 stopwatch_reset.config(state='disabled')
def timer_counter(label):
        def count():
                global timer_running
                if timer_running:
                        global timer_counter_num
                        if timer_counter_num==66600:
                            for i in range(3):
                                    display="Time Is Up"
                                    if platform.system() == 'Windows':
                                        winsound.Beep(5000,1000)
                                    elif platform.system() == 'Darwin':
                                        os.system('say Time is Up')
                                    elif platform.system() == 'Linux':
                                        os.system('beep -f 5000')
                            timer_running=False
                            timer('reset')
                        else:
                                tt = datetime.datetime.fromtimestamp(timer_counter_num) 
                                string = tt.strftime("%H:%M:%S") 
                                display=string
                                timer_counter_num -= 1
                        label.config(text=display)
                        label.after(1000, count)
        count()
def timer(work):
         if work == 'start':
                 global timer_running, timer_counter_num
                 timer_running=True
                 if timer_counter_num == 66600:
                         timer_time_str = timer_get_entry.get()
                         hours,minutes,seconds=timer_time_str.split(':')
                         minutes = int(minutes)  + (int(hours) * 60)
                         seconds = int(seconds) + (minutes * 60)
                         timer_counter_num = timer_counter_num + seconds  
                 timer_counter(timer_label)
                 timer_start.config(state='disabled')
                 timer_stop.config(state='enabled')
                 timer_reset.config(state='enabled')
                 timer_get_entry.delete(0,END)
         elif work == 'stop':
                 timer_running=False
                 timer_start.config(state='enabled')
                 timer_stop.config(state='disabled')
                 timer_reset.config(state='enabled')
         elif work == 'reset':
                 timer_running=False
                 timer_counter_num=66600
                 timer_start.config(state='enabled')
                 timer_stop.config(state='disabled')
                 timer_reset.config(state='disabled')
                 timer_get_entry.config(state='enabled')
                 timer_label.config(text = 'Timer')
tabs_control = Notebook(window)
clock_tab = Frame(tabs_control)
alarm_tab = Frame(tabs_control)
stopwatch_tab = Frame(tabs_control)
timer_tab = Frame(tabs_control)
tabs_control.add(clock_tab, text="Clock")
tabs_control.add(alarm_tab, text="Alarm")
tabs_control.add(stopwatch_tab, text='Stopwatch')
tabs_control.add(timer_tab, text='Timer')
tabs_control.pack(expand = 1, fill ="both")
time_label = Label(clock_tab, font = 'calibri 40 bold', foreground = 'black')
time_label.pack(anchor='center')
date_label = Label(clock_tab, font = 'calibri 40 bold', foreground = 'black')
date_label.pack(anchor='s')
get_alarm_time_entry = Entry(alarm_tab, font = 'calibri 15 bold')
get_alarm_time_entry.pack(anchor='center')
alarm_instructions_label = Label(alarm_tab, font = 'calibri 10 bold', text = "Enter Alarm Time. Eg -> 01:30 PM, 01 -> Hour, 30 -> Minutes")
alarm_instructions_label.pack(anchor='s')
set_alarm_button = Button(alarm_tab, text = "Set Alarm", command=alarm)
set_alarm_button.pack(anchor='s')
alarm_status_label = Label(alarm_tab, font = 'calibri 15 bold')
alarm_status_label.pack(anchor='s')
stopwatch_label = Label(stopwatch_tab, font='calibri 40 bold', text='Stopwatch')
stopwatch_label.pack(anchor='center')
stopwatch_start = Button(stopwatch_tab, text='Start', command=lambda:stopwatch('start'))
stopwatch_start.pack(anchor='center')
stopwatch_stop = Button(stopwatch_tab, text='Stop', state='disabled',command=lambda:stopwatch('stop'))
stopwatch_stop.pack(anchor='center')
stopwatch_reset = Button(stopwatch_tab, text='Reset', state='disabled', command=lambda:stopwatch('reset'))
stopwatch_reset.pack(anchor='center')
timer_get_entry = Entry(timer_tab, font='calibiri 15 bold')
timer_get_entry.pack(anchor='center')
timer_instructions_label = Label(timer_tab, font = 'calibri 10 bold', text = "Enter Timer Time. Eg -> 01:30:30, 01 -> Hour, 30 -> Minutes, 30 -> Seconds")
timer_instructions_label.pack(anchor='s')
timer_label = Label(timer_tab, font='calibri 40 bold', text='Timer')
timer_label.pack(anchor='center')
timer_start = Button(timer_tab, text='Start', command=lambda:timer('start'))
timer_start.pack(anchor='center')
timer_stop = Button(timer_tab, text='Stop', state='disabled',command=lambda:timer('stop'))
timer_stop.pack(anchor='center')
timer_reset = Button(timer_tab, text='Reset', state='disabled', command=lambda:timer('reset'))
timer_reset.pack(anchor='center')
clock()
window.mainloop()

 

이제 터미널이나 명령 줄 또는 IDE / 편집기에서 간단히 코드를 실행할 수 있습니다. 터미널에서 아래와 같은 실행 명령으로 실행하시면 아주 아름다운 디지털 시계가 나옵니다. 실행 명령은

 

$python3 digital_clock.py

 

입니다. 잘 작동합니다. 아래 보는 화면은 윈도 창 크기와 폰트 크기를 바꾼 화면입니다. 보기 좋습니다. 고생하셨는데 아래 하나만 더 해주세요. 

 

여기까지 하셨으면 이제 라즈베리파이가 부팅하면서 시계가 뜨게 하는 게 마지막이죠?  다음 링크 "라즈베리파이 부팅하면서 프로그램 윈도우에서 자동 시작"을 참고하시면 아주 쉽게 하실 수 있습니다.

 

그럼 이만. 총총. 

 

아름다운 디지털 시계

 

 

 

 

 

 

반응형