美文网首页
基于tkinter的网罗天下商机信息查询工具

基于tkinter的网罗天下商机信息查询工具

作者: mr_酱 | 来源:发表于2018-11-15 08:58 被阅读14次

全部代码

#-*- coding: utf-8 -*-

import requests
import urllib3
import json
import tkinter as tk

class Wltx:
    # auth请求地址
    auth_url = 'https://wltx.cmcc-cs.cn:8981/net/api/auth/login?appId=wltx16dfba1448&appSecret=99b14a119e7c0c0639aa1f67ec8693a6&userId=201804282156'
    # 根据商机id查询招标信息地址
    zb_url = 'https://wltx.cmcc-cs.cn:8981/net/api/net/busi/biddDetail'
    auth_code = None

    def __init__(self):
        self.getAuthCode()

    def getHeaders(self):
        headers = {
            'accept':'*/*',
            'Accept-Encoding':'gzip',
            'User-Agent':'okhttp/3.6.0',
            'Content-Type': 'application/json;charset=utf-8',
        }
        if self.auth_code is not None:
            headers['authorization'] = self.auth_code
            return headers
        else:
            return headers
            
    def getAuthCode(self):
        # get请求
        r = requests.get(self.auth_url, headers = self.getHeaders(), verify=False)
        if r.status_code == 200:
            content = json.loads(r.text)
            if 'access_token' in content.keys():
                token = content['access_token']
                self.auth_code = token
            else:
                pass
        else:
            # 网络请求异常
            pass

    def getZbById(self, busi_optny_id):
        data = 'belgProvCode=00030018&busiOptnyId='+ busi_optny_id +'&userId=201804282156'
        r = requests.post(self.zb_url, data=data, headers = self.getHeaders(), verify=False)
        if r.status_code == 200:
            content = json.dumps(json.loads(r.text), ensure_ascii=False, indent=2)
            return content
        else:
            pass
    

class App:
    win = tk.Tk()
    # 设置窗口标题
    win.title('ES数据核查')
    # 设置窗口宽度
    width = 500
    # 设置窗口高度
    height =700
    # 获取屏幕宽度
    screen_width  = win.winfo_screenwidth()
    # 获取屏幕高度
    screen_height = win.winfo_screenheight()
    # 窗口据中显示
    win.geometry("%dx%d+%d+%d" %(width, height, (screen_width-width)/2,(screen_height-height)/2))
    # 窗口最大值
    win.maxsize(500,700)
    # 窗口最小值
    win.minsize(500,700)

    # 招标信息查询页面
    tk.Label(win, text='   请输入商机id:').pack(pady=10)
    en1 = tk.Entry(win, width=50)
    en1.insert('end', '181107130532320006')
    en1.pack()
    # 搜索按钮
    but1 = tk.Button(win, text='搜索', bg='green', fg='#ffffff', bd=1, width=50)
    but1.pack(pady=10)
    text1 = tk.Text(win, width=70, height=70)
    text1.config(state='disabled')
    text1.pack(pady=10)
    wltx = Wltx()
    def __init__(self):
        self.but1.bind('<Button-1>',self.getZbById)
        self.win.mainloop()

    def getZbById(self, event):
        busi_optny_id = self.en1.get()
        content = self.wltx.getZbById(busi_optny_id)
        self.text1.config(state='normal')
        self.text1.delete(1.0,'end')
        self.text1.insert('end', content)
        self.text1.config(state='disabled')

if __name__ == "__main__":
    app = App()

运行效果

image.png

使用pyinstaller 打包

pyinstaller -Fw demo.py

pyinstall 参数说明:

参数 说明
-F, –onefile 产生一个文件用于部署 (参见XXXXX).
-D, –onedir 产生一个目录用于部署 (默认)
-K, –tk 在部署时包含 TCL/TK
-a, –ascii 不包含编码.在支持Unicode的python版本上默认包含所有的编码.
-d, –debug 产生debug版本的可执行文件
-w,–windowed,–noconsole 使用Windows子系统执行.当程序启动的时候不会打开命令行(只对Windows有效)
-c,–nowindowed,–console 使用控制台子系统执行(默认)(只对Windows有效)
-s,–strip 可执行文件和共享库将run through strip.注意Cygwin的strip往往使普通的win32 Dll无法使用.
-X, –upx 如果有UPX安装(执行Configure.py时检测),会压缩执行文件(Windows系统中的DLL也会)(参见note)
-o DIR, –out=DIR 指定spec文件的生成目录,如果没有指定,而且当前目录是PyInstaller的根目录,会自动创建一个用于输出(spec和生成的可执行文件)的目录.如果没有指定,而当前目录不是PyInstaller的根目录,则会输出到当前的目录下.
-p DIR, –path=DIR 设置导入路径(和使用PYTHONPATH效果相似).可以用路径分割符(Windows使用分号,Linux使用冒号)分割,指定多个目录.也可以使用多个-p参数来设置多个导入路径
–icon=<FILE.ICO> 将file.ico添加为可执行文件的资源(只对Windows系统有效)
–icon=<FILE.EXE,N> 将file.exe的第n个图标添加为可执行文件的资源(只对Windows系统有效)
-v FILE, –version=FILE 将verfile作为可执行文件的版本资源(只对Windows系统有效)
-n NAME, –name=NAME 可选的项目(产生的spec的)名字.如果省略,第一个脚本的主文件名将作为spec的名字

相关文章

网友评论

      本文标题:基于tkinter的网罗天下商机信息查询工具

      本文链接:https://www.haomeiwen.com/subject/hmsefqtx.html