본문 바로가기

카테고리 없음

Python 윈도우 종료 프로그램

tkinter를 이용해서 조금 수정했다.(재부팅 추가)

PyQt5를 주로 사용했었는데  tkinter도 간단히 사용하기 편하고 좋다.

import tkinter as tk
import os
import tkinter.messagebox as messagebox

root = tk.Tk()

root.title("프로그램 종료")
root.attributes('-toolwindow', True) # 윈도우창 접기 버튼 없애기
root.resizable(False, False)

width = 260
heigt = 50

# 창 크기 및 위치
x = root.winfo_screenwidth() # 가로 넓이
y = root.winfo_screenheight() # 세로 넓이
left_top_x = int(x/2-width/2) #중앙에 위치시키기 위한 창의 가로 이동값, 좌표값은 정수
left_top_y = int(y/2-heigt/2) # 중앙에 위치시키기 위한 창의 세로 이동값, 좌표값은 정수
root.geometry('{}x{}+{}+{}'.format(width,heigt,left_top_x,left_top_y)) # 크기 설정


def selHalt() :
    # messagebox.showinfo("알림", "시스템종료")
    os.system("shutdown /s /t 0")

def selreboot() :
    # messagebox.showinfo("알림", "재부팅")
    os.system("shutdown /r /t 0")

def selCancel() :
    messagebox.showinfo("알림", "작업을 취소 하였습니다.")
    root.quit()


button1 = tk.Button(root, text="시스템종료", fg="red", font=("Arial", 10, "bold"), command=selHalt) # fg="red", bg="blue"
button2 = tk.Button(root, text="재  부  팅", fg="blue", font=("Arial", 10, "bold"), command=selreboot)
button3 = tk.Button(root, text="취      소", font=("Arial", 10, "bold"), command=selCancel)

button1.grid(row=0, column=0, padx=10, pady=10)
button2.grid(row=0, column=1, padx=10, pady=10)
button3.grid(row=0, column=2, padx=10, pady=10)


root.mainloop()