'gnome inspect, get gtk widget under cursor

I am developing an application that can inspect the GUI of gnome application (inspect any application widget like windows accessibilityinsights not only one app).

I want to know in gtk, is there any way to get the widget under the cursor?



Solution 1:[1]

I recommend using an exception handler (try/except). Here's one way to do it:

difficulty = 3

def get_list_from_user():   # Prompt the user for a list of number
    while True:
        user_list = input(f"Enter {difficulty} numbers separated by space: ").split()
        try:
            user_list = [int(i) for i in user_list]
            if len(user_list) != difficulty:
                raise ValueError
            return user_list
        except ValueError:
            print('Invalid input')

print(get_list_from_user())

Solution 2:[2]

You could use a try, except statement. If the int() fails, it will throw a exception which we handle.

        try:
            user_list = [int(i) for i in user_list]
        except ValueError:
            print("Invalid value")

Full code:

def get_list_from_user():   # Prompt the user for a list of number
    while True:
        user_list = input(f"Enter {difficulty} number separated by space: ")
        user_list = user_list.split()
        try:
            user_list = [int(i) for i in user_list]
        except ValueError:
            print("Invalid value")
            continue
    
        if not len(user_list) == difficulty:
            print(f"Please chose {difficulty} number separated by space: ")
        else:
            break

    saved_user_list = user_list
    return saved_user_list

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Albert Winestein
Solution 2 9769953