Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python
- # -*- coding: utf-8 -*-
- # Importamos lo módulos necesarios
- import os
- import sys
- from tkinter import *
- # Obtenemos el usuario logueado y creamos las funciones que van a ser comandos de los botones.
- usuario = os.getlogin()
- def reiniciar():
- os.system("/usr/bin/systemctl reboot")
- def apagar():
- os.system("/usr/bin/systemctl poweroff")
- def salir():
- os.system("sudo /usr/bin/loginctl terminate-seat seat0")
- def suspender():
- os.system("/usr/bin/systemctl suspend")
- def hibernar():
- os.system("/usr/bin/systemctl hibernate")
- def bloquear():
- os.system("/usr/bin/xflock4")
- # Creamos la clase que incluye la ventana sin decoración , etiqueta para el título, los botones para las acciones y la configuración de cada elemento.
- class closingDialog:
- def __init__(self):
- self.v0 = Tk ()
- w = 235
- h = 215
- sw=self.v0.winfo_screenwidth()
- sh = self.v0.winfo_screenheight()
- x = (sw - w)/2
- y = (sh - h)/2
- self.v0.geometry('%dx%d+%d+%d' % (w, h, x, y))
- self.v0.overrideredirect(1)
- self.v0.config(bg="black")
- photo0=PhotoImage(file="/home/" + usuario + "/.icons/logout.png")
- photo1=PhotoImage(file="/home/" + usuario + "/.icons/reboot.png")
- photo2=PhotoImage(file="/home/" + usuario + "/.icons/shutdown.png")
- photo3=PhotoImage(file="/home/" + usuario + "/.icons/hibernate.png")
- photo4=PhotoImage(file="/home/" + usuario + "/.icons/suspend.png")
- photo5=PhotoImage(file="/home/" + usuario + "/.icons/lock-screen.png")
- photo6=PhotoImage(file="/home/" + usuario + "/.icons/cancel.png")
- self.label1=Label(self.v0,height=2,width=25,bg="#606060",fg="cyan",font=("Arial", 12, "bold"),text = "Cerrar sesión de " + usuario).grid(row=0,column=0,sticky=W+E+N+S,columnspan=3,pady=2)
- self.b1=Button(self.v0,height=48,width=48,relief=FLAT,fg="blue",font=("Arial", 9, "bold"),text="Salir",image=photo0,compound=TOP,command=lambda: salir()).grid(row=1,column=0,padx=1, pady=1)
- self.b2=Button(self.v0,height=48,width=48,relief=FLAT,fg="brown",font=("Arial", 9, "bold"),text="Reiniciar",image=photo1,compound=TOP,command=lambda: reiniciar()).grid(row=1,column=1,padx=1, pady=1)
- self.b3=Button(self.v0,height=48,width=48,relief=FLAT,fg="red",font=("Arial", 9, "bold"),text="Apagar",image=photo2,compound=TOP,command=lambda: apagar()).grid(row=1,column=2,padx=1,pady=1)
- self.b4=Button(self.v0,height=48,width=48,relief=FLAT,fg="#483D8B",font=("Arial", 9, "bold"),text="Hibernar",image=photo3,compound=TOP,command=lambda: hibernar()).grid(row=2,column=0,padx=1,pady=1)
- self.b5=Button(self.v0,height=48,width=48,relief=FLAT,fg="#3672B4",font=("Arial", 9, "bold"),text="Suspender",image=photo4,compound=TOP,command=lambda: suspender()).grid(row=2,column=1,padx=1,pady=1)
- self.b6=Button(self.v0,height=48,width=48,relief=FLAT,fg="magenta",font=("Arial", 9, "bold"),text="Bloquear",image=photo5,compound=TOP,command=lambda: bloquear()).grid(row=2,column=2,padx=1,pady=1)
- self.b7=Button(self.v0,height=26,width=48,relief=FLAT,fg="black",font=("Arial", 10, "bold"),text="Cancelar",image=photo6,compound=LEFT,command=self.v0.quit).grid(row=3,column=0,columnspan=3,sticky=W+E+N+S, padx=1,pady=1)
- self.v0.mainloop()
- # Cuando el script inicia, "closingDialog" instancia "app" es creada y su función "__init__"es ejecutada. La ventana principal v0, label, y botones son creados . Finalmente se ejecuta la mainloop de "v0" y la aplicación queda a la espera de eventos (como clicks del mouse)
- if __name__ == "__main__":
- app = closingDialog()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement