使用 glade 在 python GTK 中激活和禁用复选框
Check box active and diactive in pythonGTK using glade
我要为下图编写代码:
我想告诉如果勾选为真可以进入用户并通过如果登录的勾选为假则不能进入用户并通过。这是 xml
空地文件:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkLayout" id="layout1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkCheckButton" id="checkbutton1">
<property name="label" translatable="yes">Login</property>
<property name="use_action_appearance">False</property>
<property name="width_request">150</property>
<property name="height_request">30</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="x">10</property>
<property name="y">10</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry1">
<property name="width_request">150</property>
<property name="height_request">30</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="placeholder_text">Username</property>
</object>
<packing>
<property name="x">10</property>
<property name="y">40</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry2">
<property name="width_request">150</property>
<property name="height_request">30</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="placeholder_text">Password</property>
</object>
<packing>
<property name="x">170</property>
<property name="y">40</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
您需要将回调连接到 Login CheckButton,通过调用它们的小部件 set_sensitive(sensitive)
方法来切换两个 Entry 小部件的灵敏度。
来自GTK2 docs:
def set_sensitive(sensitive)
sensitive : if True make the widget sensitive
The set_sensitive()
method sets the "sensitive" property of the widget
to the value specified by sensitive. If sensitive is True the widget
will be sensitive and the user can interact with it. An insensitive
widget appears "grayed out" and the user can't interact with it.
Insensitive widgets are known as "inactive", "disabled", or "ghosted"
in some other toolkits.
我可以 post GTK2 中的一个小例子,如果有帮助的话。
我要为下图编写代码:
我想告诉如果勾选为真可以进入用户并通过如果登录的勾选为假则不能进入用户并通过。这是 xml
空地文件:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkLayout" id="layout1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkCheckButton" id="checkbutton1">
<property name="label" translatable="yes">Login</property>
<property name="use_action_appearance">False</property>
<property name="width_request">150</property>
<property name="height_request">30</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="x">10</property>
<property name="y">10</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry1">
<property name="width_request">150</property>
<property name="height_request">30</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="placeholder_text">Username</property>
</object>
<packing>
<property name="x">10</property>
<property name="y">40</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry2">
<property name="width_request">150</property>
<property name="height_request">30</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="placeholder_text">Password</property>
</object>
<packing>
<property name="x">170</property>
<property name="y">40</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
您需要将回调连接到 Login CheckButton,通过调用它们的小部件 set_sensitive(sensitive)
方法来切换两个 Entry 小部件的灵敏度。
来自GTK2 docs:
def set_sensitive(sensitive)
sensitive : if True make the widget sensitive
The
set_sensitive()
method sets the "sensitive" property of the widget to the value specified by sensitive. If sensitive is True the widget will be sensitive and the user can interact with it. An insensitive widget appears "grayed out" and the user can't interact with it. Insensitive widgets are known as "inactive", "disabled", or "ghosted" in some other toolkits.
我可以 post GTK2 中的一个小例子,如果有帮助的话。