【发布时间】:2017-03-19 20:58:25
【问题描述】:
我使用脚本:
#!/usr/bin/python
from uuid import getnode as get_mac
import socket
import requests
import datetime
import os
def main():
print('start')
i = datetime.datetime.now()
#print ("Current date & time = %s" % i)
headers = {"Content-Type": "text/html; charset=UTF-8"}
r = requests.post("http://michulabs.pl", data={'name' : 'CI17nH', 'ip' : getIp(), 'mac' : getMac(), 'source' : 'so', 'join_date' : i})
print(r.status_code, r.reason)
print(r.text) # TEXT/HTML
print(r.status_code, r.reason) # HTTP
os.system('zenity --warning --text="It is part of master thesis. \nThis script is safe but you should never open files from untrusted source. \nThanks for help!"')
"""
method to read ip from computer
it will be saved in database
"""
def getIp():
ip = socket.gethostbyname(socket.gethostname())
print 'ip: ' + str(ip)
return ip
"""
method to read mac from computer
it will be saved in database
"""
def getMac():
mac = get_mac()
print 'mac: ' + str(mac)
return mac
if __name__ == "__main__":
main()
它在 Linux(Kali Linux)上运行良好,但是当我在 Windows 上使用它时(通过 py2exe 创建 .exe 文件后)消息框弹出然后立即消失,无需等待单击“确定”。如何强制它等待点击按钮?
【问题讨论】:
-
只是一个猜测,但我认为脚本退出,消息框也是如此,主进程的子进程。
-
@PedroLobito 好的,所以我可以在弹出消息后进行假等待(例如 10 秒),但这不是我想要的。在 Windows 上单击“确定”后必须有关闭程序的解决方案
-
您可能想要使用 tkinter 并在框按钮中添加一个观察者。
标签: python python-2.7 zenity