色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python tkinter實(shí)現(xiàn)定時(shí)關(guān)機(jī)

瀏覽:2日期:2022-06-21 18:01:24

本文實(shí)例為大家分享了python tkinter實(shí)現(xiàn)定時(shí)關(guān)機(jī)的具體代碼,供大家參考,具體內(nèi)容如下

很早以前寫的,懶得修改,代碼很簡(jiǎn)單,適合初學(xué)者

運(yùn)行效果圖如下:

python tkinter實(shí)現(xiàn)定時(shí)關(guān)機(jī)

使用注意 設(shè)定時(shí)間后點(diǎn)擊開始即可實(shí)現(xiàn)定時(shí)關(guān)機(jī),同時(shí)窗口也會(huì)關(guān)閉 想要取消關(guān)機(jī)的話,再次打開,點(diǎn)取消即可 代碼如下

import os,time# import multiprocessingimport threadingfrom tkinter import *from tkinter import ttkimport tkinter.messagebox as message_boxwindow =Tk()window.title(’auto_shutdown’)window.geometry(’240x180’)window.resizable(False, False)window.update() var = StringVar()var1 = StringVar()var2 = StringVar()# 設(shè)置func為守護(hù)線程def funcs(): t = threading.Thread(target=func) t.setDaemon(True) t.start()# 執(zhí)行自動(dòng)關(guān)機(jī)指令def func(): #彈出messagebox警告提示 message_box.showwarning('Warning', 'Your pc will shutdown at %s : %s' % (var.get(),var1.get())) print(’wohaizai’) mytime = time.strftime(’%H:%M:%S’) h2 = mytime[0:2] m2 = mytime[3:5] s2 = mytime[6:] print(h2) print(m2) print(s2) print(var.get()) print(var1.get()) # 算出距離關(guān)機(jī)時(shí)間的秒數(shù) count_down_second=-int(h2)*3600-int(m2)*60-int(s2)+int(var.get())*3600+int(var1.get())*60+int(var2.get()) # 如果關(guān)機(jī)設(shè)置在第二天,結(jié)果加86400(一天的總秒數(shù)) if count_down_second<0: count_down_second=count_down_second+86400 os.system('shutdown -s -t %s' % count_down_second) print(count_down_second) window.quit()# 快捷關(guān)機(jī)選項(xiàng)入口def fun_set1(): cb_h.current(18)def fun_set2(): cb_h.current(21)def fun_set3(): cb_h.current(22)def fun_set4(): cb_h.current(23)def funcq(): os.system(’shutdown -a’)# 定義三個(gè)容器,方便布局root = ttk.LabelFrame(window, text='定時(shí)關(guān)機(jī)')root.grid(column=0, row=0,padx=2, pady=2)root1 = ttk.LabelFrame(window, text='常用時(shí)間')root1.grid(column=1, row=0,padx=2, pady=2)root2 = ttk.LabelFrame(window, text='開始')root2.grid(column=0, row=1,columnspan=2,padx=2, pady=2)Label(root,text=’:’).grid(column=1, row=0,padx=2, pady=5)cb_h = ttk.Combobox(root,width=3,textvariable =var)a = []for i in range(10): a.append((’0’+str(i)))for i in range(10,24): a.append(i) cb_h[’values’] =tuple(a)cb_h.current(0)cb_h.grid(column=0, row=0,padx=2, pady=5)cb_m = ttk.Combobox(root,width=3,textvariable =var1)b = []for i in range(10): b.append(’0’+str(i))for i in range(10,60): b.append(str(i)) cb_m[’values’] =tuple(b)cb_m.current(0)cb_m.grid(column=2, row=0,padx=2, pady=5)cb_s = ttk.Combobox(root,width=3,textvariable =var2)c = []for i in range(10): c.append(’0’+str(i))for i in range(10,60): c.append(str(i)) cb_s[’values’] =tuple(c)cb_s.current(0)cb_s.grid(columnspan=3, row=1,padx=2, pady=6)Button(root1,text = ’18:00’,command = fun_set1).grid(column=0, row=0,padx=2, pady=2)Button(root1,text = ’21:00’,command = fun_set2).grid(column=1, row=0,padx=2, pady=2)Button(root1,text = ’22:00’,command = fun_set3).grid(column=0, row=1,padx=2, pady=2)Button(root1,text = ’23:00’,command = fun_set4).grid(column=1, row=1,padx=2, pady=2)b1=Button(root2,text = ’開始’,command = funcs,height =2,width =6)b1.grid(column=0, row=0,padx=24, pady=2)b1=Button(root2,text = ’取消’,command = funcq,height =2,width =6)b1.grid(column=1, row=0,padx=24, pady=2)root.mainloop()

項(xiàng)目的github地址

ps:已打包為exe格式,可在dist目錄下找到

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 深夜福利亚洲 | 黄色三级三级三级 | 国产一区成人 | 国产亚洲欧美日韩在线看片 | 一区二区三区欧美 | 国产成人ay手机在线观看 | 亚洲精品一区二区三区中文字幕 | 亚州免费一级毛片 | 精品丝袜国产自在线拍亚洲 | 国产香蕉尹人综合在线观 | 在线成人精品国产区免费 | 久久综合精品国产一区二区三区无 | 最新怡红院全部视频在线 | 特级a做爰全过程片 | 天堂素人搭讪系列嫩模在线观看 | 三级国产三级在线 | 久久日本三级韩国三级 | 99热久久国产精品一区 | 亚洲一区二区中文 | 亚洲天堂影院在线观看 | 深夜福利视频在线看免费 | 亚洲午夜精品久久久久久抢 | 国产精品国产 | 成人a毛片高清视频 | 在线一区国产 | 国产日韩精品一区二区在线观看 | 一级片免费网址 | 久久大陆| 中国二级毛片 | 国产精品日韩欧美在线 | 成人毛片网站 | 久久在线免费观看视频 | 可以免费观看欧美一级毛片 | 久久综合精品视频 | 亚洲美女色成人综合 | 国产精品7m凸凹视频分类大全 | 日本伊人精品一区二区三区 | 亚洲精品国产经典一区二区 | 成人黄色三级 | 久草视频中文 | 欧美成人伊人十综合色 |