Python implements methods that call a window based on the window title

  • 2020-04-02 14:39:34
  • OfStack

This article illustrates how a python implementation invokes a window based on the window title. Share with you for your reference. Specific analysis is as follows:

When you know the title of a Windows window, you can call the window with the following code, or even write to the window.


#-*-coding:utf-8-*-
import win32gui,win32con
# Below is the title name of the window, which must be wrong, but works fine in the console 
# Write it down in the file U coding 
a=u"jb51.net"
dlg=win32gui.FindWindow(None,a)
//Use the control's ID to get a handle to the control, simulate writing input field text, and press the submit button
t1=win32gui.GetDlgItem(dlg,1012)
t2=win32gui.GetDlgItem(dlg,1001)
k1=win32gui.GetDlgItem(dlg,1605)
win32gui.SendMessage(t1,win32con.WM_SETTEXT,None,'902723')
win32gui.SendMessage(t2,win32con.WM_SETTEXT,None,'761209')
win32gui.SendMessage(k1,win32con.BM_CLICK,None,None)

I hope this article has helped you with your Python programming.


Related articles: