Laresss

Shutdown Scheduler with Tkinter

Aug 5th, 2021 (edited)
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. # !/usr/bin/env python
  2. # coding: UTF-8
  3. #
  4. #   Algoritmo que gera uma interface gráfica para
  5. #   agendar o desligamento do computador.
  6. #
  7. #   @author: Alex Lares
  8. #   @since: 05/08/2021
  9. #
  10.  
  11. import os
  12. from tkinter import *
  13.  
  14.  
  15. # Função para desligar
  16. def comando(segundos):
  17.     tempo = "60*" + segundos
  18.     tempo = eval(tempo)
  19.     tempo = str(tempo)
  20.     os.system("shutdown -s -t " + tempo)
  21.  
  22.  
  23. # Função geradora da janela
  24. def janelinha():
  25.     root = Tk()
  26.     root.configure(bg='#BD5652')
  27.     root.title('Shutdown Scheduler')
  28.     root.geometry('300x200')
  29.     root.resizable(0, 0)
  30.     x = (root.winfo_screenwidth() - root.winfo_reqwidth()) / 2
  31.     y = (root.winfo_screenheight() - root.winfo_reqheight()) / 2
  32.     root.geometry("+%d+%d" % (x, y))
  33.  
  34.     # Texo superior
  35.     Label(text='Agendador de Desligamento', font='Arial 15', bg='#BD5652').pack(side=TOP)
  36.     Label(text='\nDigite em quantos minutos o computador \n deverá ser desligado.\n',
  37.           bg='#BD5652').pack(side=TOP)
  38.  
  39.     # Barra de entrada
  40.     seg = StringVar()
  41.     barra = Entry(root, width='20', font="Courier 17", textvariable=seg)
  42.     barra.pack()
  43.  
  44.     # Botão de confirmação
  45.     b1 = Button(root, text="Confirmar", width=10, command=lambda: comando(seg.get()))
  46.     b1.place(x=20, y=150)
  47.  
  48.     # Botão de cancelamento
  49.     b2 = Button(root, text="Cancelar Agendamento", width=20, command=lambda: os.system("shutdown -a"))
  50.     b2.place(x=130, y=150)
  51.  
  52.     root.mainloop()
  53.  
  54.  
  55. janelinha()
  56.  
Add Comment
Please, Sign In to add comment