【发布时间】:2017-09-10 05:21:30
【问题描述】:
我一直在尝试编写一个 python 程序来自动关闭我的计算机。通知消息框模块使用 tkinter 代码,如 TutorialPoint。弹出窗口将显示是/否选项。 使用当前代码,只有当我按下“No”按钮时,系统才会关闭。
因此,它应该自动启动关机过程,而无需我单击任何内容。同时,如果我单击“是”,则关机过程应该停止。
这是代码。我如何做到这一点?
import MessageBox
def PopUp(Title, Msg, Type='Info'):
Title = str(Title)
Msg = str(Msg)
root = tk.Tk()
root.withdraw()
if Type == "Question":
response = MessageBox.askquestion(Title, Msg)
print("question", response)
return response
elif Type == "TryAgain":
response = MessageBox.askretrycancel(Title, Msg)
print("try again", response)
return response
else:
print("Incorrect Type selected.")
response = MessageBox.showinfo(Title, Msg)
print("info", response)
return response
def main():
CurrentTime = int(time.strftime('%H'))
if CurrentTime > 22 or CurrentTime < 5:
msg = ("The Time is %s hours. Abort Automatic Shutdown?" % CurrentTime)
resp1 = Notification.PopUp("Auto Shut Down", msg, Type="Question")
print('Response from Notification is %s' % resp1)
if resp1 == 'no':
closeApps()
shutDown()
else:
print('ShutDown abortered by user.')
if __name__ == '__main__':
main()
【问题讨论】:
标签: python windows python-3.x tkinter popup