用python给我做一个工具包包括小闹钟,计算器,自动关机,记事本,网站打开器,快捷键盘等
时间: 2024-05-16 22:13:33 浏览: 67
好的,以下是一个基于Python的工具包,其中包括小闹钟、计算器、自动关机、记事本、网站打开器、快捷键盘等功能。
```python
import time
import webbrowser
import os
from tkinter import *
from tkinter import messagebox
# 小闹钟
def alarm():
alarm_time = entry1.get()
while True:
time.sleep(1)
current_time = time.strftime("%H:%M:%S")
if current_time == alarm_time:
messagebox.showinfo("Alarm", "Time's up!")
break
# 计算器
def calculate():
expression = entry2.get()
try:
result = eval(expression)
messagebox.showinfo("Result", f"The result is {result}")
except:
messagebox.showerror("Error", "Invalid expression")
# 自动关机
def shutdown():
time = int(entry3.get())
os.system(f"shutdown /s /t {time}")
# 记事本
def notepad():
os.system("notepad")
# 网站打开器
def open_website():
website = entry5.get()
webbrowser.open(website)
# 快捷键盘
def shortcut():
root2 = Toplevel()
root2.title("Shortcuts")
root2.geometry("300x200")
label = Label(root2, text="Press Ctrl + C to copy")
label.pack(pady=10)
def copy():
root.clipboard_clear()
root.clipboard_append(entry6.get())
root.bind("<Control-c>", lambda x: copy())
# 创建GUI
root = Tk()
root.title("Toolbox")
root.geometry("400x500")
# 小闹钟
label1 = Label(root, text="Alarm Clock")
label1.pack(pady=10)
entry1 = Entry(root, width=10, font=("Helvetica", 20))
entry1.pack(pady=10)
button1 = Button(root, text="Set Alarm", command=alarm)
button1.pack(pady=10)
# 计算器
label2 = Label(root, text="Calculator")
label2.pack(pady=10)
entry2 = Entry(root, width=30, font=("Helvetica", 20))
entry2.pack(pady=10)
button2 = Button(root, text="Calculate", command=calculate)
button2.pack(pady=10)
# 自动关机
label3 = Label(root, text="Shutdown Timer (in secs)")
label3.pack(pady=10)
entry3 = Entry(root, width=10, font=("Helvetica", 20))
entry3.pack(pady=10)
button3 = Button(root, text="Shutdown", command=shutdown)
button3.pack(pady=10)
# 记事本
label4 = Label(root, text="Notepad")
label4.pack(pady=10)
button4 = Button(root, text="Open Notepad", command=notepad)
button4.pack(pady=10)
# 网站打开器
label5 = Label(root, text="Website Opener")
label5.pack(pady=10)
entry5 = Entry(root, width=30, font=("Helvetica", 20))
entry5.pack(pady=10)
button5 = Button(root, text="Open Website", command=open_website)
button5.pack(pady=10)
# 快捷键盘
label6 = Label(root, text="Shortcut Keyboard")
label6.pack(pady=10)
entry6 = Entry(root, width=30, font=("Helvetica", 20))
entry6.pack(pady=10)
button6 = Button(root, text="Open Shortcuts", command=shortcut)
button6.pack(pady=10)
root.mainloop()
```
你可以在控制台中运行这个程序,或者将代码保存到.py文件中,双击运行。
阅读全文