我正在学习AutoIT,并且正在尝试编写一个允许GUI的脚本 用户输入几个值,单击确定按钮,然后查看相同的值 在点击另一个OK按钮之前再次显示,退出脚本。
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
Local $file, $btn, $msg
Local $width1, $width2, $iOldOpt
local $startangle, $endangle, $nomeas, $time
GUICreate("My GUI",370,160) ; will create a dialog box that when displayed is centered
$iOldOpt = Opt("GUICoordMode", 2)
$width1 = 300
$width2 = 50
GUICtrlCreateLabel("Startvinkel i förhållande till referensriktningen (grader):", 10, 30, $width1)
$startangle = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Slutvinkel i förhållande till referensriktningen (grader):", -($width1+$width2), 0, $width1)
$endangle = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Antal mätriktningar:", -($width1+$width2), 0, $width1)
$nomeas = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Mättid i varje riktning (sekunder):", -($width1+$width2), 0, $width1)
$time = GUICtrlCreateInput("", 0, -1, $width2)
$iOldOpt = Opt("GUICoordMode", 1)
$btn = GUICtrlCreateButton("Ok", 155, 130, 60, 20)
GUISetState(@SW_SHOW)
$msg = 0
; Loop until the user exits.
While $msg <> $GUI_EVENT_CLOSE
$msg = GUIGetMsg()
Select
Case $msg = $btn
ExitLoop
EndSelect
WEnd
GUICreate("My GUI",370,160) ; will create a dialog box that when displayed is centered
$iOldOpt = Opt("GUICoordMode", 2)
GUICtrlCreateLabel("Startvinkel i förhållande till referensriktningen (grader):", 10, 30, $width1)
GUICtrlCreateLabel(GUICtrlRead($startangle), 0, -1, $width2)
GUICtrlCreateLabel("Slutvinkel i förhållande till referensriktningen (grader):", -($width1+$width2), 0, $width1)
GUICtrlCreateLabel(GUICtrlRead($endangle), 0, -1, $width2)
GUICtrlCreateLabel("Antal mätriktningar:", -($width1+$width2), 0, $width1)
GUICtrlCreateLabel(GUICtrlRead($nomeas), 0, -1, $width2)
GUICtrlCreateLabel("Mättid i varje riktning (sekunder):", -($width1+$width2), 0, $width1)
GUICtrlCreateLabel(GUICtrlRead($time), 0, -1, $width2)
$iOldOpt = Opt("GUICoordMode", 1)
$btn = GUICtrlCreateButton("Ok", 155, 130, 60, 20)
While $msg <> $GUI_EVENT_CLOSE
$msg = GUIGetMsg()
Select
Case $msg = $btn
ExitLoop
EndSelect
WEnd
MsgBox($MB_SYSTEMMODAL, "Finished", GUICtrlRead($nomeas))
EndFunc
脚本启动,显示第一个GUI并让我输入我的值,但是当我单击“确定”按钮时没有任何反应。这是为什么?
此脚本在某种程度上基于编码示例,其中单击“确定”按钮会引导您进入“消息框”,如脚本的后半部分所示。我所做的就是删除MsgBox() - 行并使用GUICreate()重新执行它。没有其他任何改变。
答案 0 :(得分:1)
这样的东西?
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
Local $file, $btn, $msg
Local $width1, $width2, $iOldOpt
Local $startangle, $endangle, $nomeas, $time
GUICreate("My GUI", 570, 260) ; will create a dialog box that when displayed is centered
$iOldOpt = Opt("GUICoordMode", 2)
$width1 = 300
$width2 = 50
GUICtrlCreateLabel("Startvinkel i förhållande till referensriktningen (grader):", 10, 30, $width1)
$startangle = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Slutvinkel i förhållande till referensriktningen (grader):", -($width1 + $width2), 0, $width1)
$endangle = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Antal mätriktningar:", -($width1 + $width2), 0, $width1)
$nomeas = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Mättid i varje riktning (sekunder):", -($width1 + $width2), 0, $width1)
$time = GUICtrlCreateInput("", 0, -1, $width2)
$iOldOpt = Opt("GUICoordMode", 1)
$btn = GUICtrlCreateButton("Ok", 155, 130, 60, 20)
$1 = GUICtrlCreateLabel("Startvinkel i förhållande till referensriktningen (grader):", 10, 160, 500, 20)
$2 = GUICtrlCreateLabel("Slutvinkel i förhållande till referensriktningen (grader):", 10, 180, 500, 20)
$3 = GUICtrlCreateLabel("Antal mätriktningar:", 10, 200, 500, 20)
$4 = GUICtrlCreateLabel("Mättid i varje riktning (sekunder):", 10, 220, 500, 20)
GUISetState(@SW_SHOW)
$msg = 0
; Loop until the user exits.
While $msg <> $GUI_EVENT_CLOSE
$msg = GUIGetMsg()
Select
Case $msg = $btn
;~ MsgBox($MB_SYSTEMMODAL, "Finished", 'Antal mätriktningar: ' & GUICtrlRead($nomeas))
GUICtrlSetData($1, GUICtrlRead($1) & ', ' & GUICtrlRead($nomeas))
GUICtrlSetData($2, GUICtrlRead($2) & ', ' & GUICtrlRead($endangle))
GUICtrlSetData($3, GUICtrlRead($3) & ', ' & GUICtrlRead($time))
GUICtrlSetData($4, GUICtrlRead($4) & ', ' & GUICtrlRead($startangle))
GUICtrlSetData($nomeas, '')
GUICtrlSetData($endangle, '')
GUICtrlSetData($time, '')
GUICtrlSetData($startangle, '')
EndSelect
WEnd
EndFunc ;==>Example
答案 1 :(得分:0)
我想你想要这个
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
Local $file, $btn, $msg
Local $width1, $width2, $iOldOpt
Local $startangle, $endangle, $nomeas, $time
GUICreate("My GUI", 370, 160) ; will create a dialog box that when displayed is centered
$iOldOpt = Opt("GUICoordMode", 2)
$width1 = 300
$width2 = 50
GUICtrlCreateLabel("Startvinkel i förhållande till referensriktningen (grader):", 10, 30, $width1)
$startangle = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Slutvinkel i förhållande till referensriktningen (grader):", -($width1 + $width2), 0, $width1)
$endangle = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Antal mätriktningar:", -($width1 + $width2), 0, $width1)
$nomeas = GUICtrlCreateInput("", 0, -1, $width2)
GUICtrlCreateLabel("Mättid i varje riktning (sekunder):", -($width1 + $width2), 0, $width1)
$time = GUICtrlCreateInput("", 0, -1, $width2)
$iOldOpt = Opt("GUICoordMode", 1)
$btn = GUICtrlCreateButton("Ok", 155, 130, 60, 20)
GUISetState(@SW_SHOW)
$msg = 0
; Loop until the user exits.
While $msg <> $GUI_EVENT_CLOSE
$msg = GUIGetMsg()
Select
Case $msg = $btn
MsgBox($MB_SYSTEMMODAL, "Finished", 'Antal mätriktningar: ' & GUICtrlRead($nomeas))
GUICtrlSetData($nomeas, '')
GUICtrlSetData($endangle, '')
GUICtrlSetData($time, '')
GUICtrlSetData($startangle, '')
EndSelect
WEnd
EndFunc ;==>Example