1.2 效果展示

2)Tkinter 界面化小程序
2.1 附源码项目
from tkinter import ttkimport osimport tkinter.messagebox as message_boxwindows = tkinter.Tk()windows.title("Python 定时关机")# window 居中 windows.update()# update window ,must docurWidth = 280# get current widthcurHeight = windows.winfo_reqheight()# get current heightscnWidth, scnHeight = windows.maxsize()# get screen width and height# now generate configuration informationconfig = '%dx%d+%d+%d' % (curWidth, curHeight,(scnWidth - curWidth) / 2, (scnHeight - curHeight) / 2)windows.geometry(config)# root 容器 root = ttk.LabelFrame(windows, text="关机命令")root.grid(column=0, row=0, padx=15, pady=15)# 提醒文本 tkinter.Label(root, text="输入时间").grid(column=0, row=0, sticky=tkinter.W)tkinter.Label(root, text="选择").grid(column=1, row=0)# 存储输入的值 time = tkinter.StringVar()unit = tkinter.StringVar()# 输入框 time_edit = tkinter.Entry(root, width=10, textvariable=time)time_edit.grid(column=0, row=1, padx=4, sticky=tkinter.W)time_edit.focus()# 下拉单位选择 unit_arr = ('时', '分', '秒')unit_chosen = ttk.Combobox(root, width=6, textvariable=unit, state='readonly')unit_chosen['values'] = unit_arrunit_chosen.grid(column=1, row=1)unit_chosen.current(0)def change_edit(to_time):time_edit.delete(0, 10)time_edit.insert(0, to_time)unit_chosen.current(1)# startdef start():if time.get() and unit.get():message_box.showwarning("选择完毕", "你的电脑将在多少 %s %s" % (time.get(), unit.get()))# shutdown 的秒数count_down_second = int(time.get())if unit.get() == 'hour':count_down_second *= 3600elif unit.get() == 'minute':count_down_second *= 60# executeos.system("shutdown -s -t %s" % count_down_second)windows.quit()# canceldef cancel():os.system("shutdown -a")windows.quit()# start 按钮 start_action = tkinter.Button(root, text="START", command=start)start_action.grid(column=2, row=1)# 文本 tip_label = tkinter.Label(root, text="倒计时关机")tip_label.grid(row=2, column=0, pady=2)# 快捷选择时间 fram = tkinter.Frame(root)fram.grid(row=3, column=0, columnspan=3)# 常用的时间 for i in range(2, 7):button = tkinter.Button(fram, text=str(i * 15) + "min", command=lambda x=i: change_edit(str(x * 15)))button.grid(row=0, column=i - 2, padx=2, pady=2, sticky=tkinter.W)# cancel 按钮 cancel_action = tkinter.Button(root, text="CANCEL", command=lambda: cancel())cancel_action.grid(row=4, column=1, pady=10, sticky=tkinter.W) 2.2 效果展示

推荐阅读
- 菜咸了怎么办
- 自制磨砂膏怎么做
- 苹果榨汁后的果肉怎么处理
- 项链发黄怎么办
- wps怎么取消隐藏行
- 人生日历怎么管理应用?人生日历管理应用方法
- 使命召唤斧子怎么获得
- 苹果榨汁怎么变色了呢
- 原神如何快速刷原石
- 苹果账号密码锁定怎么办
