Reputation: 23
I need to hide "Start menu" window via python if it's open. Clicking on coordinates does not work for me because script will be running on Windows 11. Also, it would be nice if I could check if "Start menu" is visible etc.
UPD: Code that works now.
desktop = Desktop(backend='uia')
start_menu = desktop.window(title='Start', control_type='Window')
if start_menu.exists():
pywinauto.keyboard.send_keys('{LWIN down}{LWIN up}')
Upvotes: 1
Views: 1659
Reputation: 10000
If there is nothing special in Win11 (I haven't tried it yet), this is how it works on Win10:
from pywinauto import Desktop
taskbar = Desktop(backend="uia").window(title="Taskbar", control_type="Pane")
# taskbar.dump_tree() # print the subtree like it should be coded with pywinauto
# we will check if "Start" window exists later (it's kind of locator)
start_window = Desktop(backend="uia").window(title="Start", control_type="Window")
# wait up to 2 seconds until window exists or return False
# if window already exists, it returns True almost immediately
if start_window.exists(timeout=2):
# hide the menu
taskbar.child_window(title="Start", control_type="Button").click()
Upvotes: 1