0
Follow
0
View

Key sprites are added through the list box to perform corresponding tasks

dxthong 注册会员
2023-02-28 08:46

The following answers are based on ChatGPT and GISer Liu:
You can use the following steps to achieve this function:

  1. Add a task to be performed in the list box of the key sprit, such as 1234, 2341, 4312, and so on.

  2. In your code, use the pyautogui.locateOnScreen function to locate the "List item" icon in the list box and click on it using the pyautogui.click function to expand the list of tasks.

    < / li > < li >

    use pyautogui. LocateAllOnScreen function orientation to the task list of all the tasks, and save them to a list.

  3. According to the sequence of tasks that need to be executed, traverse the sequence and execute the corresponding subroutine in turn. You can use the importlib module to dynamically load and execute the corresponding subroutine. For example, if the task sequence is 4231, you can execute subtask_4, subtask_2, subtask_3, and subtask_1 in sequence.

Here is an example program that demonstrates how to execute the appropriate subroutine through the keystroke Sprite's list box:

import pyautogui
import importlib

# 定义子程序
def subtask_1():
    print("执行子程序1")

def subtask_2():
    print("执行子程序2")

def subtask_3():
    print("执行子程序3")

def subtask_4():
    print("执行子程序4")

# 执行任务序列
task_sequence = [4, 2, 3, 1]

# 定位任务列表框并单击列表项图标
listbox_icon = pyautogui.locateOnScreen("listbox_icon.png")
if listbox_icon is not None:
    pyautogui.click(listbox_icon)

# 定位任务列表中的所有任务
tasks = []
for task_image in pyautogui.locateAllOnScreen("task_*.png"):
    task_name = task_image.split("_")[1]
    tasks.append(int(task_name))

# 按照任务序列依次执行子程序
for task_number in task_sequence:
    task_name = "subtask_" + str(task_number)
    if task_number in tasks:
        module = importlib.import_module(__name__)
        subtask = getattr(module, task_name)
        subtask()
    else:
        print("未找到任务:", task_name)

In this example program, we first define four subroutines corresponding to the numbers 1, 2, 3, and 4 in the sequence of tasks. We then define a task sequence, task_sequence, where the order of the numbers represents the order of the subroutines that need to be executed. Next, we use the pyautogui.locateOnScreen function to locate the "list item" icon in the list box of the key Sprite and click on it with the pyautogui.click function to expand the list of tasks. . Then, we use pyautogui locateAllOnScreen function orientation to the task list of all the tasks, and save them to a list. Finally, we execute the corresponding subroutine in sequence of tasks. If a number in the task sequence is not in the task list, the program prints a message indicating that the corresponding task is not found.

cutecoconut 注册会员
2023-02-28 08:46

This answer partially references GPT, GPT_Pro better solution
Use the keysprit to perform the task, which can be achieved by adding the task to the list box.
For example, if you double-click left to add 1234 to right, the keystroke sprit will execute the subroutine 1234 in order, or 4231 in order if it is 4231.

First, we need to set up the task content on the key Sprite, such as creating a "task 1" :

F1:: ;定义快捷键F1
    ListBox, list_box, xm, ym, w, h ;定义列表框变量
    list_box := "[[123,456,789],["任务1","任务2","任务3","任务4","任务5","任务6","任务7","任务8","任务9","任务10"]]" ;列表框内容
    MsgBox, %list_box% ;显示列表框内容,供调试使用
    InputBox, list_box_input, 请输入子程序编号, 请输入子程序编号, , %list_box% ;让用户输入子程序编号
    SplitPath, list_box_input,,list_box_input_list  ;将用户输入的子程序编号字符串分割为列表
    Loop, Parse, list_box_input_list  ;循环执行用户输入的子程序
    {
        Run %A_LoopField% ;执行子程序
    }
    Return  ;返回

The ListBox command is used to define a list box named list_box , and set the list box contents to 123456、789 and 任务1、任务2、任务3、任务4、任务5、任务6、任务7、任务8、任务9和任务10 . The InputBox command is then used to let the user enter the subprogram's code name. The SplitPath command divides the code strings entered by the user into a list(for example, divide the input strings 123456 and 789 into three separate strings 123, 456, and 789). Finally, the Loop command is used to loop through the user-input subroutine.

Therefore, when the user double-click left to add 1234 to right on the key Sprite, the key Sprite executes the subroutine 1234 in sequence; If 4231 is entered, it is executed in the order of 4231.
If the answer is helpful, please accept it.

dingyan124 注册会员
2023-02-28 08:46

Write the subroutine to be executed as an independent function. Add the name of the subroutine to be executed in the list box. When you double-click the list box, get the name of the selected subroutine. Here is a sample code:

import tkinter as tk

def sub1():
    print("执行子程序 1")

def sub2():
    print("执行子程序 2")

def sub3():
    print("执行子程序 3")

def sub4():
    print("执行子程序 4")

def run_selected_subprogram():
    selected_program = listbox.get(listbox.curselection())
    eval(selected_program + "()")

# 创建主窗口
root = tk.Tk()

# 创建列表框并添加子程序名称
listbox = tk.Listbox(root)
listbox.insert(0, "sub1")
listbox.insert(1, "sub2")
listbox.insert(2, "sub3")
listbox.insert(3, "sub4")

# 绑定双击事件到列表框
listbox.bind("", lambda event: run_selected_subprogram())

# 显示列表框
listbox.pack()

# 运行窗口
root.mainloop()
djpraul 注册会员
2023-02-28 08:46

Using GPT and your own ideas, you can associate each item in a list box with a subroutine and run the subroutine associated with that item when the user selects it. Here is some example code that might be useful:

Suppose you have a list box named ListBox1, and you have four subroutines, Sub1, Sub2, Sub3, and Sub4.

Associates each item of the list box with a corresponding subroutine. You can add the following code to ListBox1's AddItem event:

Private Sub ListBox1_AddItem(ByVal ItemText As String)
    Select Case ItemText
        Case "1"
            ListBox1.List(ListBox1.ListCount - 1, 1) = "Sub1"
        Case "2"
            ListBox1.List(ListBox1.ListCount - 1, 1) = "Sub2"
        Case "3"
            ListBox1.List(ListBox1.ListCount - 1, 1) = "Sub3"
        Case "4"
            ListBox1.List(ListBox1.ListCount - 1, 1) = "Sub4"
    End Select
End Sub

This code associates the second column of each item with the corresponding subroutine name. For example, when the user adds the item "1" to the list box, the code assigns the name of the first subroutine "Sub1" to the second column of the item.

Runs the subroutine associated with the option. You can add the following code to the DblClick event in the list box:

Private Sub ListBox1_DblClick()
    Dim i As Integer
    For i = 0 To ListBox1.ListCount - 1
        Select Case ListBox1.List(i, 0)
            Case "1"
                Call Sub1
            Case "2"
                Call Sub2
            Case "3"
                Call Sub3
            Case "4"
                Call Sub4
        End Select
    Next i
End Sub

This code loops through each item in the list box and runs the appropriate subroutine based on the first column of that item, which is the value of the option.

If you want to execute the subprograms in the order shown in the list box, instead of executing them in the order of the option values, you can use the following code:

Private Sub ListBox1_DblClick()
    Dim i As Integer
    For i = 0 To ListBox1.ListCount - 1
        Select Case ListBox1.List(i, 1)
            Case "Sub1"
                Call Sub1
            Case "Sub2"
                Call Sub2
            Case "Sub3"
                Call Sub3
            Case "Sub4"
                Call Sub4
        End Select
    Next i
End Sub

This code executes the subroutine according to the second column of each item in the list box, the column associated with the subroutine name. Because it loops in the order in the list box, the subroutine executes in the order the user added the items.
If it is helpful to you, please accept it, thank you.

cvbnbv 注册会员
2023-02-28 08:46

The answer references chatGPT
The key sprinter can be added through the list box to perform the corresponding task, for example, by clicking the "Add" button in the "Task List" window, Then select "Keyboard Input" task in the pop-up "Add Task" window, set the text to be input, and finally click "OK" button to complete the operation of adding tasks.

About the Author

Question Info

Publish Time
2023-02-28 08:46
Update Time
2023-02-28 08:46

Related Question

如何在头部添加证书PEM/ KEY

通过几个DVs循环compare_means

连接SharePoint站点失败:列表索引超出范围

PHP for循环与foreach textarea

在尝试访问自定义数据集时获得“KeyError”

robot framework使用关键字Run Keyword If多出三个点,执行失败

导入多个Azure KeyVault访问策略

asp.net mvc Areas里面怎么添加独立的登录页面

Question: Concurrent queue with max concurrency (per cacheKey)

计数命中数并在Angular中更改API KEY