Mic*_*u93 5 python zenity python-2.7
我用脚本:
#!/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()
Run Code Online (Sandbox Code Playgroud)
它在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
Run Code Online (Sandbox Code Playgroud)
为了解决使用py2exe编译后未显示的tk窗口,您需要在设置时包含"dll_excludes": ["tcl85.dll", "tk85.dll"]内部options,这将排除导致错误的两个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
Run Code Online (Sandbox Code Playgroud)
根据评论,我认为您需要通过tkinter生成对话框。这是一个例子:
import tkMessageBox
import Tkinter as tk
root = tk.Tk()
root.withdraw()
tkMessageBox.showwarning(
"Message Title",
"Your Message")
root.destroy()
Run Code Online (Sandbox Code Playgroud)
os.system...对上面的代码进行修改
您可能想查看更多tkinter 对话框示例
| 归档时间: |
|
| 查看次数: |
2136 次 |
| 最近记录: |