简体   繁体   中英

How to check radio buttons and option list in PyQt4

In my application I have to use PyQt4, and I want to be able to check radio buttons and option list.

When I want to pass a parameter to the text field type i do this:

doc = QWebView.page().mainFrame().documentElement()
first_name = doc.findFirst("input[id=f_name]")
first_name.setAttribute("value", "John")

But how to set the value for radio button:

    <li id="signup-list-gender" class="gender" >
                    <span class="gender-label">     Gender:
<span class="formNote">(Optional)</span></span>
                    <label for="signup-gender-male"><input id="signup-gender-male" class="gender" tabindex="9" type="radio" name="gender" value="m" > Male</label>
                    <label for="signup-gender-female"><input id="signup-gender-female" class="gender" tabindex="10" type="radio" name="gender" value="f" > Female</label>
                </li>
                <li id="signup-list-birthdate" class="birthdate">

You need to set the attributed "checked" on the radio button, something like this (i did't test this code):

doc = QWebView.page().mainFrame().documentElement()
male = doc.findFirst("input[id=signup-gender-male]")
male.setAttribute("checked", "true")

For radio buttons attributes check here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM