用 Python 的 Tkinter GUI 做一让用户输入指定文字(比如叫我爸爸 0.0 哈哈哈),否则关机的程序(只合适 Windows 用户)

Windows 关机命令 shutdown

在命令行窗口输入 help shutdown 可以看到详细的参数列表

用 Tkinter 创建出输入框

1
2
3
4
5
6
7
8
9
10
11
12
13
# baibai.py
import tkinter as tk
from tkinter.simpledialog import askstring
import os
root = tk.Tk()
root.withdraw() # 隐藏tkinter的主界面
os.system('shutdown -s -t 30') # 30s内关机
x, answer = '','白白是我爸爸'
hint = '输入:'+ answer + ',否则在30s内关机!'
while x != answer:
x = askstring('askstring',hint)
if(x == answer): os.system('shutdown -a') # 用户正确输入了就不关机了
root.mainloop()

用 pyinstaller 打包

pyinstaller -F baibai.py -w

就可以在 dist 文件夹中找到对应的 exe 文件了。然后发给小伙伴让 Ta 们叫你爸爸 0.0