使用 pywinauto 检查复选框不起作用 [英] Checking a checkbox with pywinauto doesn't work

查看:51
本文介绍了使用 pywinauto 检查复选框不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 pip 安装了最后一个 pywinauto 模块.
我不知道如何使用 Check()、UnCheck()、GetCheckState() 方法.

I installed the last pywinauto module from pip.
I don't know how to use the Check(), UnCheck(), GetCheckState() methods.

这是我非常简单的代码示例.

This is my very simple code sample.

from pywinauto import application

# Start the madvr settings application.
app = application.Application()
app.start_(r'C:\Program Files\LAV Filters\x86\madVR\madHcCtrl.exe editLocalSettingsDontWait')

# Handle the madvr settings window.
madvr = app.window_(title_re="madVR.*")

# Enable the smooth motion tab.
madvr.TreeView.GetItem(r'\rendering\smooth motion').Click()

# Check the smooth motion checkbox.
madvr.TCheckBox.Check()

如果我使用 Click() 方法它可以工作,但这不是我想要的.

It works if I use the Click() method but this is not what I want.

madvr.TCheckBox.Click()

如果复选框已被选中,则取消选中它.

If the checkbox is already checked it unchecks it.

为什么我不能使用 Check() 方法?
我尝试了 Uncheck() 和 GetCheckState() 方法,它们也不起作用.

Why I can't use the Check() method?
I tried with Uncheck() and GetCheckState() methods, they didn't work too.

推荐答案

我在 0.5.1 中添加了 "TCheckBox" 类名以进行正确的复选框检测(将于本周发布).感谢您的用例.目前您可以解决它(代码已更新为 pywinauto==0.6.x):

I've added "TCheckBox" class name to make proper check box detection in 0.5.1 (will be released this week). Thanks for the use case. Currently you may workaround it so (code was updated for pywinauto==0.6.x):

from pywinauto.controls.win32_controls import ButtonWrapper
checkbox = ButtonWrapper(madvr.TCheckBox.wrapper_object())
checkbox.get_check_state()

这篇关于使用 pywinauto 检查复选框不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆