2016-03-15 160 views
1

我用tkinter编写了一个简约的python程序,当点击一个按钮时它会给出一个示例文本。我现在想的AutoIt执行该程序,然后单击按钮:鼠标点击按钮

#include <MsgBoxConstants.au3> 
#include <AutoItConstants.au3> 

CalcTime() 

Func CalcTime() 
    Run("dist/min_tk_app.exe") 
    Local $aPos = ControlGetPos("[CLASS:Button; INSTANCE:1]", "", "Edit1") 
    MsgBox($MB_SYSTEMMODAL, "", $aPos) 
    MouseClick($MOUSE_CLICK_LEFT, 324, 145, 1) 
EndFunc 

我收到这个信息:[CLASS:Button; INSTANCE:1],通过AutoIt的窗口信息应用。我总是只收到0作为$aPos的输出。你知道这是为什么吗?

回答

1

您正在使用错误的ControlGetPos

ControlGetPos ("title", "text", controlID) 

[CLASS:Button; INSTANCE:1]应尽可能controlID不要忘记窗口(重要的)的称号!

不管怎么说,而不是ControlGetPosMouseClick你应该使用ControlClick

$WinTitle = "" ; put your window title here MANDATORY or it will use active window 
$WinText = "" ;can be left empty 
ControlClick($WinTitle, $WinText, "[CLASS:Button; INSTANCE:1]") 
1

我假设您收到0作为$aPos的输出,因为窗口还没有。你可以尝试该窗口上的工作之前,使用WinWait

Run("dist/min_tk_app.exe") 

; wait 10 seconds for the window to appear 
WinWait("[CLASS:YourApp]", "", 10) 

; maybe wait another second 
Sleep(1000) 

Local $aPos = ControlGetPos("[CLASS:Button; INSTANCE:1]", "", "Edit1") 
1

@如果地铁的解决方案不工作,我会建议使用ControlFocus设置在控制焦点,然后ControlSend发送的控制ENTER键。通常OK按钮被预先选择。如果不是这种情况,那么您可以发送TAB,直到按钮获得焦点并且发送进入。