我使用脚本:
#!/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文件后(,会弹出消息框,然后立即消失,而无需等待单击"确定"。如何强制它等待点击的按钮?
tkMessageBox
几乎与使用 os.system
和 zenity
显示警告消息框相同。
import tkMessageBox as messagebox
import Tkinter as tk
root = tk.Tk() # creates a window and hide it so it doesn't show up
root.withdraw()
messagebox.showwarning(
"Error", # warning title
"It is part of master thesis. nThis script is safe but you should never open files from untrusted source. nThanks for help!") # warning message
root.destroy() # destroys the window
要解决使用 py2exe 编译后 tk 窗口未显示的问题,您需要在设置时在options
中包含"dll_excludes": ["tcl85.dll", "tk85.dll"]
,这将排除导致错误的两个 dll。
# your setup options will look something like this
setup(options = {'py2exe': {'bundle_files': 1, 'compressed': True, "dll_excludes": ["tcl85.dll", "tk85.dll"])}) # same setup file but include that too
在评论之后,我认为您需要通过 tkinter 生成对话框。下面是一个示例:
import tkMessageBox
import Tkinter as tk
root = tk.Tk()
root.withdraw()
tkMessageBox.showwarning(
"Message Title",
"Your Message")
root.destroy()
更改上述代码的os.system...
您可能需要查看更多 tkinter 对话框示例