第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何使用 tkinter 制作計(jì)時(shí)器?

如何使用 tkinter 制作計(jì)時(shí)器?

大話西游666 2021-10-19 17:19:29
我正在嘗試制作一個(gè)計(jì)時(shí)器來關(guān)閉我運(yùn)行 linux 的計(jì)算機(jī)。選擇我使用 spinbox 的時(shí)間。所以想法是選擇旋轉(zhuǎn)框中的時(shí)間量,然后添加到命令sudo shutdown -P+ 15 分鐘(例如示例)。直到現(xiàn)在它才關(guān)閉,我無法用簡單的方法來做到這一點(diǎn)。from tkinter import *import osimport timedef shutdown():    hrs = spin1.get()    command1 = ('sudo shutdown -P')    #sum1 = command1 + hrs    os.system('sudo shutdown -P') + ('hrs')    print(os.system)def cancel():    command = ('sudo shutdown -c')    os.system('sudo shutdown -c')    print(command)'''def hrs():    spn1 = spin1.get()    dsp1 = spn1    lbltime ['text'] = dsp1'''entry_width = 2win = Tk()spin1 = IntVar()spn = IntVar()win.title('SHUTDOWN')win.geometry('300x250+300+150')lbl = Label(win, text='SET YOUR SHUTDOWN')lbl.place(x=80, y=30)spin1 = Spinbox(win, from_=00, to=23, font=('arial',26,'bold'), width= entry_width, textvariable=spin1)spin1.insert(0, '00')spin1.place(x=130, y=60)setup = Button(win, text='SET TIMER', font=('arial',16,'bold'), command=lambda :shutdown())setup.place(x=90, y=130)cnc = Button(win, text='CANCEL', font=('verdana',10, 'bold'),command= lambda :cancel())cnc.place(x=120, y=180)win.mainloop()
查看完整描述

1 回答

?
料青山看我應(yīng)如是

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超8個(gè)贊

為了將您的hrs(由用戶選擇的分鐘數(shù))添加到您的命令中,您可以簡單地將其添加到現(xiàn)有的字符串命令中,使用+或使用format()我在我的解決方案中顯示的方法。此外,在運(yùn)行sudo需要輸入密碼的命令時(shí),要自動(dòng)執(zhí)行此操作,您可以使用 -S 參數(shù)使 sudo 從 STDIN 讀取密碼,這里"mypassword"。


def shutdown():

    hrs = spin1.get()

    sd_command = 'echo mypassword | sudo -S shutdown -P +' + hrs # both will work

    sd_command = 'echo mypassword | sudo -S shutdown -P +{}'.format(hrs)

    os.system(command)

    print(command)


def cancel():

    cancel_command = 'echo mypassword | sudo -S shutdown -c'

    os.system(cancel_command)

    print(cancel_command)

如果要添加有關(guān)關(guān)機(jī)計(jì)劃的消息,則需要添加另一個(gè)標(biāo)簽,此處shutdown_schedule將顯示var_scheduletkinter 字符串變量的內(nèi)容,該內(nèi)容將在用戶計(jì)劃或取消關(guān)機(jī)時(shí)進(jìn)行修改。


def shutdown():

    hrs = spin1.get()


    sd_time = time.strftime("%H:%M", time.localtime(time.time() + 60*int(hrs)))

    var_schedule.set('Shutdown scheduled for {}'.format(sd_time))


    sd_command = 'echo mypassword | sudo -S shutdown -P +' + hrs # both will work

    sd_command = 'echo mypassword | sudo -S shutdown -P +{}'.format(hrs)

    os.system(command)

    print(command)


def cancel():

    var_schedule.set('Shutdown not scheduled yet')


    cancel_command = 'echo mypassword | sudo -S shutdown -c'

       os.system(cancel_command)

    print(cancel_command)


var_schedule = StringVar()

var_schedule.set('Shutdown not scheduled yet')


shutdown_schedule = Label(win, textvariable=var_schedule)

shutdown_schedule.place(x=130, y=30)


查看完整回答
反對(duì) 回復(fù) 2021-10-19
  • 1 回答
  • 0 關(guān)注
  • 321 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)