自学python练手,做一个APK小工具

在工作过程中,遇到了一些关于安装apk时以及安装apk后的小问题。
比如安装完apk后发现apk的版本安装错误,或者遇到要启动一些apk进行测试的问题,就做了一些启动某个apk或者卸载某个apk的小脚本。但是在桌面上摆着四五个脚本又显得有些杂乱,所以顺便将这些脚本集合了一下,并用python做了一个图形界面

from tkinter import *
import tkinter.messagebox
import os
import time
win = Tk()  # 创建窗口
win.title("APK工具")  # 窗口名字
win.geometry("350x350")  # 窗口大小


def scan():
    n = 0
    while True:
        bat_path2 = os.path.abspath(".")
        bat = os.listdir(bat_path2)
        for i in bat:
            if "start.txt" not in bat:
                bat_path1 = os.path.abspath(".")
                os.system(os.path.join(bat_path1, "devices.bat"))
                txt = open("devices.txt").read()
                txt_list = txt.split("\n")
                txt_list = [x for x in txt_list if x != ""]  
                n += 1
                print "Scanning----------"
                print "Refresh : ", n
                print "Connect Devices : ", len(txt_list) - 1
                if len(txt_list) - 1 > 0:
                    bat_path1 = os.path.abspath(".")
                    os.system(os.path.join(bat_path1, "devices_id.bat"))
                    time.sleep(2)  # 沉睡两秒
                    os.system("cls")  # 清空之前显示
                else:
                    time.sleep(2)
                    os.system("cls")
            if i == "start.txt":
                break
            break


def start():
    devices_package = os.popen("adb shell pm list package").read()  # 获取设备应用包
    if "应用" in devices_package:
        os.system("adb shell am start -n 应用进程")  # 启动应用
        tkinter.messagebox.showinfo(title="启动应用", message="应用已启动")  # 创建弹窗
    else:
        tkinter.messagebox.showinfo(title="启动应用", message="未找到应用")


def uninstall():
    os.system("adb uninstall 应用包")  # 卸载应用
    devices_package = os.popen("adb shell pm list package").read()
    if "应用" in devices_package:
        os.system("adb uninstall 应用")
    tkinter.messagebox.showinfo(title="卸载APK", message="已卸载")


# 创建按键
one = Button(win, text="扫描设备", command=scan, width=10, height=3)
two = Button(win, text="启动应用", command=start, width=10, height=3)
three = Button(win, text="卸载APK", command=uninstall, width=10, height=3)
one.pack(pady=15) 
two.pack(pady=15)
three.pack(pady=15)
win.mainloop()

在使用过程中,遇到了一个问题:在开始扫描设备后,由于扫描设备的脚本一直在循环,因此无法使用运行和卸载应用的功能,停止扫描设备就必须扫描到开始安装apk时由apk的脚本生成的start.txt文档。而且用pyinstaller打包成exe文件时不能用-w关闭命令行,因为扫描设备的脚本需要在命令行输出信息。
为解决这两个问题苦思冥想了好几天,凭借自己的浅显水平实在得不到解决,索性直接放弃并投入使用,还算不错——至少自己用着感觉不错

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值