时钟程序(仅UI部分)
# -*- coding: cp936 -*-
'''一个时钟程序'''
def createAlarm(master):
''' 创建时间选择组件,包括小时、分钟、秒
系统默认的时间设置为当前的事件'''
import time
now = time.localtime(time.time())
lfAlarm = LabelFrame(text = 'Add you alarm')
vHour = StringVar()
vHour.set(now[3])
Label(lfAlarm,text = 'Hour:').grid(row = 0,column = 0)
omHour = apply(OptionMenu,(lfAlarm,vHour) + tuple(range(0,24)))
omHour.grid(row = 0,column = 1)
vMinute = StringVar()
vMinute.set(now[4])
Label(lfAlarm,text = 'Minute:').grid(row = 0,column = 2)
omHour = apply(OptionMenu,(lfAlarm,vMinute) + tuple(range(0,60)))
omHour.grid(row = 0,column = 3)
vSecond = StringVar()
vSecond.set(now[5])
Label(lfAlarm,text = 'Second:').grid(row = 0,column = 4)
omHour = apply(OptionMenu,(lfAlarm,vSecond) + tuple(range(0,60)))
omHour.grid(row = 0,column = 5)
lfAlarm.grid(row = 1,column =0,columnspan = 6)
def addAlarm(master):
'''将当前的设置添加为一个提醒'''
pass
def setAlarm(master):
Button(master,
text = 'Add an alarm',
command = addAlarm
).grid(row = 2,column = 0,columnspan = 6)
def createAlarmList(master):
'''创建提醒列表,目前所有可用的提醒均显示在这里'''
lbAlarm = Listbox(master)
lbAlarm.grid(row = 3,column = 0,
columnspan = 4,rowspan = 3,
stick = S + N + E + W)
def createOperation(master):
'''创建操作列表,对提醒列表中的提醒进行添加、修改或删除'''
Button(master,text = 'Add alarm'
).grid(
row = 3,column = 4,
columnspan = 2,
stick = S + N + E + W)
Button(master,text = 'Modify alarm'
).grid(
row = 4,column = 4,
columnspan = 2,
stick = S + N + E + W)
Button(master,text = 'Delete alarm'
).grid(row = 5,column = 4,
columnspan = 2,
stick = S + N + E + W)
def showCurrentTime(master):
'''显示当前时间'''
lbCurrentTime = Label(master,text = 'Current Time:')
lbCurrentTime.grid(row = 0,column = 0,
columnspan = 2,
stick = W)
vCurrentTime = StringVar()
etCurrentTime = Entry(master,textvariable = vCurrentTime)
etCurrentTime.grid(row = 0,column = 2,
columnspan = 4,
stick = S + N + E + W)
from Tkinter import *
root = Tk()
showCurrentTime(root)
createAlarm(root)
createAlarmList(root)
createOperation(root)
root.mainloop()