Python writes a screenshot tool for Android devices under Windows

Source: Internet
Author: User

Use Python's wx Library to write a UI interface that will output the Android device to a computer screen, as long as the ADB is installed and the Python library involved is installed. The code is as follows:

ImportWx,subprocess,os,platformclassAutyframe (WX. Frame):def __init__(self): WX. Frame.__init__(Self, None,-1,'Android Auty', size= (350, 300)) Self.panel= WX. Panel (self,-1)        #Android devices Combox.Combox_list =[] R= Execute_shell ("ADB devices")         forIinchRange (1,len (r)-1): Combox_list.append (R[i].split ("\ t") [0]) wx. Statictext (Self.panel,-1,"Select Devices:", (15, 15)) Self.devices_combobox= Wx.combobox (Self.panel,-1, R[1].split ("\ t") [0], (15, 35), WX. DefaultSize, Combox_list, WX. Cb_dropdown)#Capture button.Self.capture_button = wx. Button (Self.panel,-1,"Capture", pos= (188, +), size= (66,25)) Self.reload_button= WX. Button (Self.panel,-1,"Reload", pos= (258, +), size= (66,25) Self . Bind (WX. Evt_button, Self.captureclick, Self.capture_button) self. Bind (WX. Evt_button, Self.reloadclick, Self.reload_button) Self.capture_button. SetDefault () Self.reload_button. SetDefault ()defCaptureclick (Self, event): Capture_android (Self.devices_combobox. GetValue ())if("Windows" inchPlatform.platform ()): Os.startfile ("D:\\screenshot.png")    defReloadclick (Self, event): Self.devices_combobox. Clear () K= Execute_shell ("ADB devices")         forIinchRange (1,len (k)-1): Self.devices_combobox. Append (K[i].split ("\ t") [0]) Self.devices_combobox. SetValue (k[1].split ("\ t") [0])defExecute_shell (Shell): P= subprocess. Popen (shell,shell=true,stdout=subprocess. PIPE) out=P.stdout.readlines ()return outdefcapture_android (device_id): Sh1="adb-s"+device_id+"shell/system/bin/screencap-p/sdcard/screenshot.png"SH2="adb-s"+device_id+"pull/sdcard/screenshot.png d:/screenshot.png"Execute_shell (SH1) Execute_shell (SH2)if __name__=='__main__': App=WX. Pysimpleapp () Autyframe (). Show () app. Mainloop ()

Run:

Advantages:

1. Running faster than uiautomatorviewer, quicker than monitor;

2. Can be selected for a plurality of devices, screen cutting;

3. After the screenshot (saved in the D packing directory "screenshot.png" file) will automatically open;

4. After plugging the device, you can reload reload the device list.

Python writes an Android device tool under Windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.