标签:接口 2.3 抓包 char ntp 部分 发送 pass hello
python一般用来写纯脚本的居多,但也可以做有视图的产品出来,例如做网页和客户端工具。做成工具的好处是,让不懂代码的人也能使用,不需要去修改代码里面的参数,如果使用次数频繁,甚至比纯脚本跟节约时间;最大的好处是打包后可以运行在任何没有安装脚本中第python三方包的电脑上,也可以运行在任何没有安装python的电脑上。下面上我很久之前的tkinter做的第一个测试工具的源代码。
此部分是tkinter代码,直接运行代码,就可以弹出界面。
1 # -*- coding: utf-8 -*- 2 from Tkinter import * 3 from PIL import Image, ImageTk 4 import urllib 5 import urllib2 6 #import http.cookiejar 7 import base64 8 import cookielib,time,sys 9 #import mysql.connector 10 import MySQLdb 11 12 13 14 15 class post(): ##########这种cookie方式略微复杂些,脚本写的太早了,是urllib2,用requests会简化很多 16 def __init__(self,values): 17 self.values=values 18 def qinqiu(self): 19 #从文件中获取cookie并访问 20 cookie = cookielib.MozillaCookieJar() 21 #从文件中读取cookie内容到变量 22 cookie.load(‘cookie.txt‘, ignore_discard=True, ignore_expires=True) 23 #利用urllib2的build_opener方法创建一个opener 24 #print ‘saddsafsdafdsf‘,cookie 25 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie)) 26 27 url ="http://www.xxxx.cn/test/yuanzhao/controls/api.php" 28 29 data = base64.b64encode(self.values) #######视情况而定,一般公司的接口参数并不需要base64进行编码 30 #print data # 31 req = urllib2.Request(url, data) 32 response = opener.open(req) 33 the_page = response.read() 34 print the_page 35 return the_page 36 37 38 class select(): ####可以不用mysql,直接请求特定的某些接口,取出我们需要的返回值也可以。 39 def __init__(self,sql): 40 self.sql=sql 41 def chaxun(self): 42 conn=MySQLdb.connect(host=‘112.xx.xx.xx‘,user=‘root‘,passwd=‘*************‘,db=‘ld_logistic_sys_******‘,port=3307) 43 cur=conn.cursor() 44 try: 45 #sql=‘select settlement_ID,payableAccount from bus_waybill,bus_waybill_fee where bus_waybill.waybillCode=bus_waybill_fee.waybillCode and bus_waybill.waybillCode=‘+str(yundanhao) 46 sql=self.sql 47 cur.execute(sql) 48 data = cur.fetchall() 49 except: 50 print u‘没查询出来‘ 51 52 53 #print data 54 cur.close() 55 conn.close() 56 return data 57 58 59 def tanchu(str1,height): #####从tkinter主界面弹出 60 top = Toplevel() 61 h=int(height) 62 top.title(‘提示‘) 63 Label(top, text=str1,fg=‘yellow‘,bg=‘red‘).pack() 64 top.geometry(‘400x‘+str(h)+‘+700+500‘) 65 return 66 67 #tanchu(‘hello‘,500) 68 69 70 71 72 def fun2(): 73 74 ydgs1=ydgs.get() 75 if ydgs1==‘‘: 76 print u‘请填写运单个数‘ 77 tanchu(u‘请填写运单个数‘,100) 78 return 79 print "创建%s个运单"%(ydgs1) 80 81 if ydnx.get()==u‘货物托运凭证‘: 82 ydnx1=0 83 elif ydnx.get()==u‘吊装受理开单‘: 84 ydnx1=1 85 else: 86 ydnx1=2 87 #print ydnx1 88 89 90 if jsfs.get()==u‘现付‘: 91 jsfs1=0 92 elif jsfs.get()==u‘提付‘: 93 jsfs1=1 94 elif jsfs.get()==u‘回单付‘: 95 jsfs1=2 96 else: 97 jsfs1=3 98 #print jsfs1 99 100 yundanneixin=ydnx1 101 jiesuanfangshi=jsfs1 102 yundangeshu=ydgs1 103 fhkhid1=fhkhid.get() 104 str1=‘创建的运单‘ 105 for i in range (int(yundangeshu)): 106 #创建运单 107 108 values = ‘{"opFrom":"1","userName":"testy","psd_v":"0","waybillType":"‘+str(yundanneixin)+‘","originatingStation":"25","destinationStation":"27","goodsNO":"名称很长的长货号a1",109 "deliveClientName":"‘+str(fhkhid1)+‘","deliveClientPhone":"13156983698","deliveClientAdd":"财务发货客户1的详细地址财务发货客户1的详细地址","receiptClientName":"101",110 "receiptClientPhone":"13698563214","receiptClientAdd":"财务收货客户2的详细地址财务收货客户2的详细地址财务收货客户2的详细地址","settleAccountType":"‘+str(jiesuanfangshi)+‘","receivable":40,111 "buisnessList":[{"buisnessType":"业务类型1业务类型1","articleName":"长品名长品名长品名长","articleNO":"长品号长品号长品号长","count":"1","weight":"1.11","volume":"1.12",112 "pack":"长包装1长包装1长包","freight":"1.13","handlingCharges":"1.14","transportationCharges":"1.15","delayUnloadCharges":"2","advanceCharges":"3",113 "other":"5.22","tax":"12.32%","paymentDay":"一年165天12个月"},{"buisnessType":"业务类型2业务类型2","articleName":"长2名长品名长品名长","articleNO":"长2号长品号长2号长",114 "count":"2","weight":"11","volume":"","pack":"","freight":"5","handlingCharges":"",115 "transportationCharges":"6","delayUnloadCharges":"","advanceCharges":"","other":"",116 "tax":"","paymentDay":"一年265天12个月"},{"buisnessType":"","articleName":"","articleNO":"品号3",117 "count":"","weight":"","volume":"","pack":"","freight":"",118 "handlingCharges":"","transportationCharges":"","delayUnloadCharges":"","advanceCharges":"","other":"","tax":"","paymentDay":""},119 {"buisnessType":"业务类型4业务类型4","articleName":"","articleNO":"","count":"","weight":"","volume":"","pack":"长包装4长包装4长包",120 "freight":"7.36","handlingCharges":"","transportationCharges":"8","delayUnloadCharges":"","advanceCharges":"","other":"","tax":"",121 "paymentDay":""}],"receipted":10,"settler":"18","receiptStatus":0,"performance":"","remark":"运单的备注中新网10月13日电 据法新社13日报道122 ,联合国大会正式任","method":"new_waybill"}‘ 123 124 cjyd=post(values) 125 the_page=cjyd.qinqiu() 126 str1=str1+the_page 127 128 #print str1 129 tanchu(str1,400) 130 131 132 ########################################################调度函数#################################################### 133 def diaodu(): 134 if ddjsfs.get()==u‘现付‘: 135 jiesuanfangshi=0 136 elif ddjsfs.get()==u‘回单付‘: 137 jiesuanfangshi=2 138 else: 139 jiesuanfangshi=3 140 141 #print jiesuanfangshi 142 143 global ydksid 144 global ydjsid 145 if ydksid.get()==‘‘ : 146 tanchu(u‘请填写运单结开始和结束id‘,100) 147 print u‘请填写运单结开始和结束id‘ 148 149 return 150 if ydjsid.get()==‘‘ : 151 print u‘请填写运单开始和结束id‘ 152 153 top = Toplevel() 154 top.title(‘提示‘) 155 Label(top, text=‘请填写运单开始和结束id!‘).pack() 156 top.geometry(‘400x300+700+500‘) 157 return 158 159 ydksid1=int(ydksid.get()) 160 ydjsid1=int(ydjsid.get())+1 161 162 163 driverid=jsyid.get() 164 gongyinshangid=gysid.get() 165 vehicleid=cphid.get() 166 167 168 169 print u‘调度‘ 170 for i in range(ydksid1,ydjsid1): 171 172 if jiesuanfangshi==0: ####运单的结算方式为0是现付,请求参数会有少量不同 173 174 175 176 177 values=‘{"opFrom":"1","userName":"ydf","psd_v":"0","supplierCompany":"‘+str(gongyinshangid)+‘","predictArriveDate":"2016-10-20","driverID":"‘+str(driverid)+‘","vehicleID":"‘+str(vehicleid)+‘","dispatchNO":178 "调度号很长很很长的aaaa111111","dispatchCharges":"5","packCharges":0,"handlingCharges":"2.22","forkliftCharges":0,"otherCharges":"4.44","settleType":"‘+str(jiesuanfangshi)+‘","settleStatus":179 "0","dispatchTotalCharges":"11.66","paidDispatchTotalCharges":"11.66","receivableKickback":"9.99","paidKickback":"9.99","settler":"32",180 "remark":"http://www.xxxx.cn/test/yuanzhao/admin/view/index.html#/dispatch/dispatchlistdispatch/522","waybillIDList":["‘+str(i)+‘"],"method":"add_dispatch"}‘ 181 else: 182 values=‘{"opFrom":"1","userName":"ydf","psd_v":"0","supplierCompany":"‘+str(gongyinshangid)+‘","predictArriveDate":"2016-10-20","driverID":"‘+str(driverid)+‘","vehicleID":"‘+str(vehicleid)+‘","dispatchNO":183 "调度号很长很很长的aaaa111111","dispatchCharges":"5","packCharges":0,"handlingCharges":"2.22","forkliftCharges":0,"otherCharges":"4.44","settleType":"‘+str(jiesuanfangshi)+‘","settleStatus":184 "0","dispatchTotalCharges":"11.66","paidDispatchTotalCharges":"6.66","receivableKickback":"9.99","paidKickback":"8","settler":"32",185 "remark":"http://www.xxxx.cn/test/yuanzhao/admin/view/index.html#/dispatch/dispatchlistdispatch/522","waybillIDList":["‘+str(i)+‘"],"method":"add_dispatch"}‘ 186 187 188 #print values 189 dd=post(values) 190 the_page=dd.qinqiu() 191 192 if ‘{"errorCode":"0","errorMsg":"","dispatchID":‘ in the_page: 193 tanchu(u‘调度成功‘,100) 194 195 196 197 198 199 ##################################根据运单id查询运单号函数############################################################ 200 def idchayundan(): 201 global dyydh 202 id=cxdydid.get() 203 if id==‘‘: 204 tanchu(u‘请输入运单id‘,100) 205 return 206 sql=‘select waybillCode from bus_waybill where ID=‘+str(id) 207 208 idcyd=select(sql) 209 the_page=idcyd.chaxun() 210 211 print the_page 212 213 dyydh1=the_page[0][0] 214 dyydhe.set(dyydh1) 215 216 217 218 219 220 def fahuo(): 221 yundanhao=fhydh.get() 222 devicename=imei.get() 223 if yundanhao==‘‘: 224 tanchu(u‘请填写运单号‘,100) 225 print (u‘请填写运单号‘) 226 return 227 228 print u‘发货‘ 229 230 values = ‘{"deviceName":"‘+str(devicename)+‘","list":[{"waybillNO":"‘+str(yundanhao)+‘"}],"method":"deliver","opFrom":"0","psd_v":"0","userName":"testy"}‘ 231 fh=post(values) 232 the_page=fh.qinqiu() 233 if ‘"errorCode":"0"‘ in the_page: 234 tanchu(u‘发货成功‘,100) 235 236 def faduanxin(): 237 yundanhao=fdxydh.get() 238 if yundanhao==‘‘: 239 tanchu(u‘请输入运单号‘,100) 240 return 241 print u‘发短信‘ 242 243 values = ‘{"waybillNO":"‘+str(yundanhao)+‘","method":"send_msg","opFrom":"0","psd_v":"0","userName":"testy"}‘ ####调用此接口会发送一条短信给收货人 244 fdx=post(values) 245 fdx.qinqiu() 246 247 def shouhuo(): 248 yundanhao=shydh.get() 249 if yundanhao==‘‘: 250 tanchu(u‘请输入运单号‘,100) 251 return 252 sql=‘select settlement_ID,payableAccount from bus_waybill,bus_waybill_fee where bus_waybill.waybillCode=bus_waybill_fee.waybillCode and bus_waybill.waybillCode=‘+str(yundanhao) 253 shsql=select(sql) 254 data=shsql.chaxun() 255 256 #print data 257 258 jsfs=data[0][0] 259 ispaid=0 260 if jsfs==0: 261 ispaid=1 262 elif jsfs==1: 263 ispaid=1 264 elif jsfs==2: 265 ispaid=0 266 elif jsfs==3: 267 ispaid=0 268 #print ispaid 269 270 rece=data[0][1] 271 #print rece 272 273 274 275 276 print u‘收货‘ 277 278 values = ‘{"consignee":"呃呃","imgUrl":"http://www.xxxx.cn/test/yuanzhao/controls/image/IMG_20160621_163048.jpg",279 "isPaid":"‘+str(ispaid)+‘","receivableMoney":"‘+str(rece)+‘","waybillNO":"‘+str(yundanhao)+‘","method":"get_receive_detail","opFrom":"0","psd_v":"0","userName":"testy"}‘ 280 281 shpost=post(values) 282 the_page=shpost.qinqiu() 283 284 if ‘"errorCode":"0"‘ in the_page: 285 286 tanchu(‘收货成功‘,100) 287 288 ######################################查询运单状态函数********************************‘‘‘ 289 def chaxunyundanzt(): 290 global ydzte 291 global cxydh 292 293 cxydh1=cxydh.get() 294 if cxydh1==‘‘: 295 print u‘请输入运单号‘ 296 297 tanchu(u‘请输入运单号‘,100) 298 return 299 300 301 #print cxydh1 302 sql=‘select status,ID from bus_waybill where waybillCode=‘+str(cxydh1) 303 cxydh2=select(sql) 304 data=cxydh2.chaxun() 305 306 307 print data 308 309 data3=data[0][1] 310 print data3,‘*********‘ 311 312 313 data1=‘‘ 314 315 if data[0][0]==1: 316 data1=u‘待调度‘ 317 elif data[0][0]==2: 318 data1=u‘待发货‘ 319 elif data[0][0]==3: 320 data1=u‘在途‘ 321 elif data[0][0]==4: 322 data1=u‘待签收‘ 323 elif data[0][0]==5: 324 data1=u‘待结算‘ 325 elif data[0][0]==6: 326 data1=u‘完成‘ 327 328 329 ydzte.set(data1) 330 yddid.set(data3) 331 332 333 ‘‘‘***********************************************tkinter**********************************************************************************************************************************************************************************************‘‘‘ 334 root = Tk() 335 root.geometry(‘580x680+200+100‘) 336 root.resizable(width = False, height = False) 337 root.title("远兆") 338 root.iconbitmap(‘yuanzhao.ico‘) 339 340 #创建运单 ***********************************************创建运单********************************************************************* 341 lb=Label(root,text = u‘创建运单‘,fg = ‘purple‘,bg = ‘green‘,width=77) 342 lb.pack(side = LEFT,padx = 0,pady = 0) 343 lb.place(x=20,y=5) 344 345 346 lb=Label(root,text = u‘创建‘,fg = ‘red‘) 347 lb.pack() 348 lb.place(x=20,y=40) 349 350 e = StringVar() #运单个数 351 ydgs = Entry(root,width = 5,textvariable = e,bg=‘#FFD700‘) 352 ydgs.pack() 353 e.set(‘10‘) 354 ydgs.place(x = 50, y = 40) 355 356 lb=Label(root,text = u‘个运单类型为‘,fg = ‘red‘) 357 lb.pack() 358 lb.place(x=90,y=40) 359 360 ydnx = StringVar(root) #运单类型, 361 ydnx.set(u‘吊装受理开单证‘) 362 om = OptionMenu(root,ydnx,u‘货物托运凭证‘,u‘吊装受理开单‘,u‘其他受理开单‘) 363 om.pack() 364 om.place(x=170,y=30) 365 366 lb=Label(root,text = u‘结算方式为‘,fg = ‘red‘) 367 lb.pack() 368 lb.place(x=300,y=40) 369 370 jsfs = StringVar(root) #结算方式 371 jsfs.set(‘回单付‘) 372 om = OptionMenu(root,jsfs,u‘现付‘,u‘提付‘,u‘回单付‘,u‘月付‘) 373 om.pack() 374 om.place(x=370,y=30) 375 376 lb=Label(root,text = u‘发货客户id为‘,fg = ‘red‘) 377 lb.pack() 378 lb.place(x=450,y=40) 379 380 e = StringVar() #发货客户id 381 fhkhid = Entry(root,width = 5,textvariable = e,bg=‘#FFD700‘) 382 fhkhid.pack() 383 e.set(‘100‘) 384 fhkhid.place(x = 525, y = 38) 385 386 387 lb=Label(root,text = u‘的运单‘,fg = ‘red‘) 388 lb.pack() 389 lb.place(x=20,y=70) 390 391 392 button = Button(root,text = u"确定创建",fg = ‘blue‘,bg = ‘#00bfff‘,width = 8,height = 1,command = fun2) 393 button.pack(side = RIGHT) 394 button.place(x = 500,y = 62) 395 396 397 #调度 ***********************************************调度********************************************************************* 398 lb=Label(root,text = u‘调度运单‘,fg = ‘purple‘,bg = ‘green‘,width=77) 399 lb.pack(side = LEFT,padx = 0,pady = 0) 400 lb.place(x=20,y=90) 401 402 lb=Label(root,text = u‘调度运单的id从‘,fg = ‘red‘) 403 lb.pack() 404 lb.place(x=20,y=120) 405 406 e = StringVar() #运单开始id 407 ydksid = Entry(root,width = 6,textvariable = e) 408 ydksid.pack() 409 #ydgs.set(‘10‘) 410 ydksid.place(x = 110, y = 120) 411 412 lb=Label(root,text = u‘至‘,fg = ‘red‘) 413 lb.pack() 414 lb.place(x=150,y=120) 415 416 e = StringVar() #运单结束始id 417 ydjsid = Entry(root,width = 6,textvariable = e) 418 ydjsid.pack() 419 #ydgs.set(‘10‘) 420 ydjsid.place(x = 170, y = 120) 421 422 lb=Label(root,text = u‘调度的供应商id为‘,fg = ‘red‘) 423 lb.pack() 424 lb.place(x=250,y=120) 425 426 e = StringVar() #供应商id 427 gysid = Entry(root,width = 4,textvariable = e,bg=‘#FFD700‘) 428 gysid.pack() 429 e.set(‘51‘) 430 gysid.place(x = 360, y = 120) 431 432 lb=Label(root,text = u‘调度的结算方式为‘,fg = ‘red‘) 433 lb.pack() 434 lb.place(x=20,y=150) 435 436 ddjsfs = StringVar(root) #调度结算方式 437 ddjsfs.set(‘现付‘) 438 om = OptionMenu(root,ddjsfs,‘现付‘,‘回单付‘,‘月付‘) 439 om.pack() 440 om.place(x=120,y=140) 441 442 lb=Label(root,text = u‘驾驶员id为‘,fg = ‘red‘) 443 lb.pack() 444 lb.place(x=220,y=150) 445 446 e = StringVar() #驾驶员id 447 jsyid = Entry(root,width = 4,textvariable = e,bg=‘#FFD700‘) 448 jsyid.pack() 449 e.set(‘32‘) 450 jsyid.place(x = 290, y = 150) 451 452 lb=Label(root,text = u‘车牌号id为‘,fg = ‘red‘) 453 lb.pack() 454 lb.place(x=350,y=150) 455 456 e = StringVar() #车牌号id 457 cphid = Entry(root,width = 4,textvariable = e,bg=‘#FFD700‘) 458 cphid.pack() 459 e.set(‘14‘) 460 cphid.place(x = 420, y = 150) 461 462 button = Button(root,text = u"确定调度",fg = ‘blue‘,bg = ‘#00bfff‘,width = 8,height = 1,command = diaodu) 463 button.pack(side = RIGHT) 464 button.place(x = 500,y = 145) 465 466 #################################id查运单号################################################# 467 lb=Label(root,text = u‘id为‘,fg = ‘purple‘) 468 lb.pack(side = LEFT,padx = 0,pady = 0) 469 lb.place(x=20,y=180) 470 471 e = StringVar() #运单id 472 cxdydid= Entry(root,width = 6,textvariable = e) 473 cxdydid.pack() 474 #ydgs.set(‘10‘) 475 cxdydid.place(x = 50, y = 180) 476 477 lb=Label(root,text = u‘的运单号是‘,fg = ‘purple‘) 478 lb.pack(side = LEFT,padx = 0,pady = 0) 479 lb.place(x=90,y=180) 480 481 dyydhe = StringVar() #对应运单号 482 dyydh= Entry(root,width = 16,textvariable = dyydhe,fg=‘#006400‘,bg=‘tan‘) 483 dyydh.pack() 484 #ydgs.set(‘10‘) 485 dyydh.place(x = 155, y = 180) 486 487 ‘‘‘ 488 ydzte = StringVar() #运单号的运单状态 489 ydzt = Entry(root,width = 8,textvariable = ydzte,fg=‘green‘) 490 ydzt.pack() 491 #ydgs.set(‘10‘) 492 ydzt.place(x = 410, y = 490) 493 ‘‘‘ 494 495 button = Button(root,text = u"点击查询",fg = ‘blue‘,bg = ‘#00ffff‘,width = 8,height = 1,command = idchayundan) 496 button.pack(side = RIGHT) 497 button.place(x = 273,y = 175) 498 499 500 501 ##############################################################发货############################################## 502 lb=Label(root,text = u‘发货‘,fg = ‘purple‘,bg = ‘green‘,width=77) 503 lb.pack(side = LEFT,padx = 0,pady = 0) 504 lb.place(x=20,y=230) 505 506 lb=Label(root,text = u‘发货的运单号‘,fg = ‘red‘) 507 lb.pack() 508 lb.place(x=20,y=260) 509 510 e = StringVar() #发货的运单号 511 fhydh= Entry(root,width = 16,textvariable = e) 512 fhydh.pack() 513 #ydgs.set(‘10‘) 514 fhydh.place(x = 110, y = 260) 515 516 lb=Label(root,text = u‘发货手机的imei‘,fg = ‘red‘) 517 lb.pack() 518 lb.place(x=250,y=260) 519 520 e = StringVar() #发货的手机imei 521 imei = Entry(root,width = 19,textvariable = e,bg=‘#FFD700‘) 522 imei.pack() 523 e.set(‘imei861483035137583‘) 524 imei.place(x = 350, y = 260) 525 526 button = Button(root,text = u"确定发货",fg = ‘blue‘,bg = ‘#00bfff‘,width = 8,height = 1,command = fahuo) 527 button.pack(side = RIGHT) 528 button.place(x = 500,y = 255) 529 530 ####################################################发短信################################################### 531 lb=Label(root,text = u‘发短信‘,fg = ‘purple‘,bg = ‘green‘,width=77) 532 lb.pack(side = LEFT,padx = 0,pady = 0) 533 lb.place(x=20,y=310) 534 535 lb=Label(root,text = u‘对‘,fg = ‘red‘) 536 lb.pack() 537 lb.place(x=20,y=340) 538 539 e = StringVar() #发短信的运单号 540 fdxydh = Entry(root,width = 16,textvariable = e) 541 fdxydh.pack() 542 #ydgs.set(‘10‘) 543 fdxydh.place(x = 50, y = 340) 544 545 lb=Label(root,text = u‘这个运单发短信‘,fg = ‘red‘) 546 lb.pack() 547 lb.place(x=170,y=340) 548 549 button = Button(root,text = u"确认发短信",fg = ‘blue‘,bg = ‘#00bfff‘,width = 8,height = 1,command = faduanxin) 550 button.pack(side = RIGHT) 551 button.place(x = 500,y = 340) 552 553 #################################################收货############################################################### 554 lb=Label(root,text = u‘收货‘,fg = ‘purple‘,bg = ‘green‘,width=77) 555 lb.pack(side = LEFT,padx = 0,pady = 0) 556 lb.place(x=20,y=390) 557 558 lb=Label(root,text = u‘收货的运单号:‘,fg = ‘red‘) 559 lb.pack() 560 lb.place(x=20,y=420) 561 562 e = StringVar() #收货的运单号 563 shydh = Entry(root,width = 16,textvariable = e) 564 shydh.pack() 565 #ydgs.set(‘10‘) 566 shydh.place(x = 110, y = 420) 567 568 button = Button(root,text = u"确认收货",fg = ‘blue‘,bg = ‘#00bfff‘,width = 8,height = 1,command = shouhuo) 569 button.pack(side = RIGHT) 570 button.place(x = 500,y = 420) 571 572 ##########‘‘‘********************************查询运单的状态*******************************‘‘‘ 573 lb=Label(root,text = u‘查询运单状态‘,fg = ‘purple‘,bg = ‘green‘,width=77) 574 lb.pack(side = LEFT,padx = 0,pady = 0) 575 lb.place(x=20,y=460) 576 577 lb=Label(root,text = u‘请输入运单号:‘,fg = ‘purple‘) 578 lb.pack() 579 lb.place(x=20,y=490) 580 581 e = StringVar() #查询的运单号 582 cxydh = Entry(root,width = 16,textvariable = e) 583 cxydh.pack() 584 #ydgs.set(‘10‘) 585 cxydh.place(x = 110, y = 490) 586 587 button = Button(root,text = u"点击查询",fg = ‘blue‘,bg = ‘#00ffff‘,width = 8,height = 1,command = chaxunyundanzt) 588 button.pack(side = RIGHT) 589 button.place(x = 273,y = 485) 590 591 lb=Label(root,text = u‘运单状态为:‘,fg = ‘purple‘) 592 lb.pack() 593 lb.place(x=340,y=490) 594 595 ydzte = StringVar() #运单号的运单状态 596 ydzt = Entry(root,width = 8,textvariable = ydzte,fg=‘#006400‘,bg=‘tan‘) 597 ydzt.pack() 598 #ydgs.set(‘10‘) 599 ydzt.place(x = 410, y = 490) 600 601 lb=Label(root,text = u‘id为:‘,fg = ‘purple‘) 602 lb.pack() 603 lb.place(x=470,y=490) 604 605 yddid = StringVar() #运单号id 606 et = Entry(root,width = 8,textvariable = yddid,fg=‘#006400‘,bg=‘tan‘) 607 et.pack() 608 #ydgs.set(‘10‘) 609 et.place(x = 505, y = 490) 610 611 612 613 ‘‘‘*********************底部图片**********************‘‘‘ 614 img = ImageTk.PhotoImage(file=‘yuanzhao.png‘) 615 lb=Label(root, text="abc", image=img) 616 lb.pack(side="top") 617 lb.place(x=0,y=540) 618 619 620 621 root.mainloop()
最后随便上两个运行时的截图。
此工具的接口使用项目的抓包接口或者参考协议文档。做这个工具的目的是,把系统主流程功能全部都放在一个界面上,因为系统分为web erp管理端和app扫码发货 收货端,每个端都是十几个页面,来回的切换页面测试,特别是web端的运单和调度需要填写大量的页面表单,是很废时间和令人狂躁的一件事情。
从代码中可以看到,tkinter的代码并不难就那几句话,后台脚本写出来了后,构建工具界面大概要多花半天时间。功能的触发是通过按钮与函数绑定,点击什么按钮就执行什么函数功能,传统的脚本方式操作想执行一个函数时候,需要把调用另一个函数的代码注释掉,这也是界面工具的一个优势吧,点什么执行什么。
上面的界面工具是直接运行代码弹出来的,脚本的文件名称是yuanzhao.py,如果想做成exe客户端,需要写另一个文件,我们取名为setup.py,其中代码如下。
1 from distutils.core import setup 2 import py2exe 3 4 #setup(windows=[‘yuanzhao.py‘]) 5 6 7 setup( 8 # targets to build 9 windows = [{"script":"yuanzhao.py", "icon_resources": [(0, "yuanzhao.ico")]} ] 10 )
运行 python setup.py py2exe,就能打包成功了,此时路径下会生成两个文件夹,
我们来看看dist文件夹就可以了。此文件就是工具的使用路径,
这样就能把dist文件夹放到任意没安装py脚本中第三方包或者没安装python的电脑运行测试工具了。
标签:接口 2.3 抓包 char ntp 部分 发送 pass hello
原文地址:http://www.cnblogs.com/ydf0509/p/6820469.html