حالت آفلاین — محتوا از حافظهٔ کش نمایش داده می‌شود

تایمر خاموش کردن سیستم

تمرین آسان 3212 visibility link download flag

برنامه ای بنویسید که عددی به عنوان ثانیه (s) از کاربر دریافت کند و پس از گذشت s ثانیه، سیستم را خاموش کند

👨‍💻 18 ساعت قبل کاربر ناشناس این تمرین رو مشاهده کرد

reply 7

visibility
import time
import os
import platform

def shutdown_system(seconds):
    """سیستم را پس از گذشت s ثانیه خاموش می‌کند."""
    print(f"سیستم پس از {seconds} ثانیه خاموش خواهد شد...")
    time.sleep(seconds)  # منتظر ماندن به مدت s ثانیه

    # بررسی سیستم عامل و اجرای دستور خاموشی
    if platform.system() == "Windows":
        os.system("shutdown /s /t 1")  # خاموش کردن در ویندوز
    elif platform.system() == "Linux" or platform.system() == "Darwin":
        os.system("shutdown now")  # خاموش کردن در لینوکس و macOS
    else:
        print("سیستم عامل پشتیبانی نمی‌شود.")

def main():
    try:
        seconds = int(input("لطفاً تعداد ثانیه‌ها را وارد کنید: "))
        if seconds < 0:
            print("لطفاً عددی مثبت وارد کنید.")
            return
        
        shutdown_system(seconds)
    except ValueError:
        print("لطفاً یک عدد صحیح وارد کنید.")

if __name__ == "__main__":
    main()

import tkinter
import os
from platform import system
def shat_down(seconds):
timer_label = tkinter.Label(frame,text="",fg='green')
timer_label.grid()
def timeing(seconds):
second = seconds
if seconds == 0:
do_shut_down()
else:
time = ''
if seconds >= 3600:
time += f"{seconds//3600}:"
seconds = seconds % 3600
if seconds >= 60:
time += f"{seconds//60}:"
seconds = seconds % 60
if seconds >= 0:
time += f"{seconds}"
timer_label.config(text=f"{time}")
second -= 1
root.after(995,timeing,second)
def do_shut_down():
def delet_error_label():
error_label.grid_forget()
error_label = tkinter.Label(text="سیستم عامل پشتیبانی نمی شود",fg="red")
if system() == "Windows":
os.system("shutdown /s /t 1")
elif system() == "Linux" or system() == "Darwin":
os.system("shutdown now")
else:
error_label.grid()
root.after(1500,delet_error_label)
return
timeing(seconds)
def start():
def delet_error_label():
error_label.grid_forget()
error_label = tkinter.Label(frame,text="",fg="red")
hours = hours_entery.get()
minutes = minutes_entery.get()
seconds = seconds_entery.get()
time = 0
if not hours and not minutes and not seconds:
error_label.config(text=".لطفا زمان را وارد کنید",fg="red")
error_label.grid()
root.after(2000,delet_error_label)
return
if 1 == 1:
if not hours:
pass
else:
time += 3600 * int(hours)
if not minutes:
pass
else:
time += 60 * int(minutes)
if not seconds:
pass
else:
time += int(seconds)
shat_down(time)
else:
error_label.config(text=".لطفا عدد وارد کنید",fg="red")
error_label.grid()
root.after(2000,delet_error_label)
return
root = tkinter.Tk()
root.title("خاموش کردن کامپیوتر")
root.geometry("400x300")
frame = tkinter.Frame(root, padx=10, pady=10,)
frame.grid(pady=20)
hours_entery = tkinter.Entry(root,width=2)
minutes_entery = tkinter.Entry(root,width=2)
seconds_entery = tkinter.Entry(root,width=2)
time_label = tkinter.Label(frame,text="زمان خاموش شدن")
start_button = tkinter.Button(frame,text="شروع",command=start)
time_label.grid(row=0,column=0)
hours_entery.grid(row=0,column=1,padx=10,pady=1)
minutes_entery.grid(row=0,column=2,padx=10,pady=1)
seconds_entery.grid(row=0,column=3,padx=10,pady=1)
start_button.grid(row=1,column=0)
root.mainloop()

import platform
import time
import os

def shutdown_system(s):
    print(f"please wait for shutdown system secend {s}")
    time.sleep(s)
    if platform.system() == 'Windows':
        os.system("shutdown /s /t 1")

number = int(input("number_secend: "))
shutdown_system(number)

windows shutdown:

    import os
    import time
    s = int(input("Enter seconds to shutdown: "))
    time.sleep(s)
    print("crtl+c for exit")
    #windows
    os.system("shutdown /s /t 1)

linux shutdown:

    import os
    import time
    s = int(input("Enter seconds to shutdown: "))
    time.sleep(s)
    print("crtl+c for exit")
    #linux
    os.system("shutdown now")

ارسال جواب

جوابت را با Markdown بنویس و ثبت کن

×
بستن