# -*- coding: utf-8 -*- #------------------------------------------------------------------------------- # Name: module1 # Author: potato # Created: 2016/07 # Copyright: P2mks.com #------------------------------------------------------------------------------- import sys from tkinter import * from datetime import datetime import serial ser = serial.Serial("COM5",38400) # シリアルポートをオープン # データを受信------------ def click_r(): print ("click data receive") # 時刻を送信---------------- def click_time_set(): print ("click time_set") ser.write("t".encode('utf-8')) ser.write(datetime.now().strftime("%Y/%m/%d %H:%M:%S").encode('utf-8')) # 時刻の表示 def show_time(): label1_var.set(datetime.now().strftime("%Y/%m/%d %H:%M:%S")) Mwin.after(1000, show_time) # 1000ms 毎 # Window の作成 ==================================================== Mwin = Tk() # ウインドウの生成 Mwin.title("デジタルクロック  p2mks.com") # タイトル Mwin.geometry("350x250+120+120") # 大きさ/配置 time_set = Button(Mwin, text = '時刻を送信',command=click_time_set) time_set.place(x = 20, y = 10, height=20, width=100) label1_var = StringVar() # ラベル文字 label1_var.set("YY/MM/DD") label1 = Label(Mwin, textvariable=label1_var) label1.place(x = 150, y = 10, height=25, width=120) # 配置、大きさ data_r = Button(Mwin, text = 'データ受信',command=click_r) data_r.place(x = 20, y = 60, height=20, width=100) list1 = Listbox(Mwin) # Text box list1.place(x = 150, y = 60, height=150, width=120) list1.insert(0,"receive data") # Main loop ========================================================== show_time() Mwin.mainloop()