Gtk.Entry
Gtk.Entry文本输入框
继承关系
Methods
| 方法修饰词 | 方法名及参数 |
|---|---|
| static | new () |
| static | new_with_buffer (buffer) |
| get_activates_default () | |
| get_alignment () | |
| get_attributes () | |
| get_buffer () | |
| get_completion () | |
| get_current_icon_drag_source () | |
| get_cursor_hadjustment () | |
| get_has_frame () | |
| get_icon_activatable (icon_pos) | |
| get_icon_area (icon_pos) | |
| get_icon_at_pos (x, y) | |
| get_icon_gicon (icon_pos) | |
| get_icon_name (icon_pos) | |
| get_icon_pixbuf (icon_pos) | |
| get_icon_sensitive (icon_pos) | |
| get_icon_stock (icon_pos) | |
| get_icon_storage_type (icon_pos) | |
| get_icon_tooltip_markup (icon_pos) | |
| get_icon_tooltip_text (icon_pos) | |
| get_inner_border () | |
| get_input_hints () | |
| get_input_purpose () | |
| get_invisible_char () | |
| get_layout () | |
| get_layout_offsets () | |
| get_max_length () | |
| get_max_width_chars () | |
| get_overwrite_mode () | |
| get_placeholder_text () | |
| get_progress_fraction () | |
| get_progress_pulse_step () | |
| get_tabs () | |
| get_text () | |
| get_text_area () | |
| get_text_length () | |
| get_visibility () | |
| get_width_chars () | |
| grab_focus_without_selecting () | |
| im_context_filter_keypress (event) | |
| layout_index_to_text_index (layout_index) | |
| progress_pulse () | |
| reset_im_context () | |
| set_activates_default (setting) | |
| set_alignment (xalign) | |
| set_attributes (attrs) | |
| set_buffer (buffer) | |
| set_completion (completion) | |
| set_cursor_hadjustment (adjustment) | |
| set_has_frame (setting) | |
| set_icon_activatable (icon_pos, activatable) | |
| set_icon_drag_source (icon_pos, target_list, actions) | |
| set_icon_from_gicon (icon_pos, icon) | |
| set_icon_from_icon_name (icon_pos, icon_name) | |
| set_icon_from_pixbuf (icon_pos, pixbuf) | |
| set_icon_from_stock (icon_pos, stock_id) | |
| set_icon_sensitive (icon_pos, sensitive) | |
| set_icon_tooltip_markup (icon_pos, tooltip) | |
| set_icon_tooltip_text (icon_pos, tooltip) | |
| set_inner_border (border) | |
| set_input_hints (hints) | |
| set_input_purpose (purpose) | |
| set_invisible_char (ch) | |
| set_max_length (max) | |
| set_max_width_chars (n_chars) | |
| set_overwrite_mode (overwrite) | |
| set_placeholder_text (text) | |
| set_progress_fraction (fraction) | |
| set_progress_pulse_step (fraction) | |
| set_tabs (tabs) | |
| set_text (text) | |
| set_visibility (visible) | |
| set_width_chars (n_chars) | |
| text_index_to_layout_index (text_index) | |
| unset_invisible_char () |
Virtual Methods
| do_activate () |
| do_backspace () |
| do_copy_clipboard () |
| do_cut_clipboard () |
| do_delete_from_cursor (type, count) |
| do_get_frame_size (x, y, width, height) |
| do_get_text_area_size (x, y, width, height) |
| do_insert_at_cursor (str) |
| do_move_cursor (step, count, extend_selection) |
| do_paste_clipboard () |
| do_populate_popup (popup) |
| do_toggle_overwrite () |
Properties
| Name | Type | Flags | Short Description |
|---|---|---|---|
| activates-default | bool | r/w/en | Whether to activate the default widget (such as the default button in a dialog) when Enter is pressed |
| attributes | Pango.AttrList | r/w/en | A list of style attributes to apply to the text of the label |
| buffer | Gtk.EntryBuffer | r/w/c/en | Text buffer object which actually stores entry text |
| caps-lock-warning | bool | r/w/en | Whether password entries will show a warning when Caps Lock is on |
| completion | Gtk.EntryCompletion | r/w/en | The auxiliary completion object |
| cursor-position | int | r | The current position of the insertion cursor in chars |
| editable | bool | r/w/en | Whether the entry contents can be edited |
| has-frame | bool | r/w/en | False removes outside bevel from entry |
| im-module | str | r/w/en | Which IM module should be used |
| inner-border | Gtk.Border | d/r/w/en | Border between text and frame. Overrides the inner-border style property deprecated |
| input-hints | Gtk.InputHints | r/w/en | Hints for the text field behaviour |
| input-purpose | Gtk.InputPurpose | r/w/en | Purpose of the text field |
| invisible-char | int | r/w/en | The character to use when masking entry contents (in “password mode”) |
| invisible-char-set | bool | r/w | Whether the invisible character has been set |
| max-length | int | r/w/en | Maximum number of characters for this entry. Zero if no maximum |
| max-width-chars | int | r/w/en | The desired maximum width of the entry, in characters |
| overwrite-mode | bool | r/w/en | Whether new text overwrites existing text |
| placeholder-text | str | r/w/en | Show text in the entry when it’s empty and unfocused |
| populate-all | bool | r/w/en | Whether to emit ::populate-popup for touch popups |
| primary-icon-activatable | bool | r/w/en | Whether the primary icon is activatable |
| primary-icon-gicon | Gio.Icon | r/w/en | Gio.Icon for primary icon |
| primary-icon-name | str | r/w/en | Icon name for primary icon |
| primary-icon-pixbuf | GdkPixbuf.Pixbuf | r/w/en | Primary pixbuf for the entry |
| primary-icon-sensitive | bool | r/w/en | Whether the primary icon is sensitive |
| primary-icon-stock | str | d/r/w/en | Stock ID for primary icon deprecated |
| primary-icon-storage-type | Gtk.ImageType | r | The representation being used for primary icon |
| primary-icon-tooltip-markup | str | r/w/en | The contents of the tooltip on the primary icon |
| primary-icon-tooltip-text | str | r/w/en | The contents of the tooltip on the primary icon |
| progress-fraction | float | r/w/en | The current fraction of the task that’s been completed |
| progress-pulse-step | float | r/w/en | The fraction of total entry width to move the progress bouncing block for each call to Gtk.Entry.progress_pulse() |
| scroll-offset | int | r/en | Number of pixels of the entry scrolled off the screen to the left |
| secondary-icon-activatable | bool | r/w/en | Whether the secondary icon is activatable |
| secondary-icon-gicon | Gio.Icon | r/w/en | Gio.Icon for secondary icon |
| secondary-icon-name | str | r/w/en | Icon name for secondary icon |
| secondary-icon-pixbuf | GdkPixbuf.Pixbuf | r/w/en | Secondary pixbuf for the entry |
| secondary-icon-sensitive | bool | r/w/en | Whether the secondary icon is sensitive |
| secondary-icon-stock | str | d/r/w/en | Stock ID for secondary icon deprecated |
| secondary-icon-storage-type | Gtk.ImageType | r | The representation being used for secondary icon |
| secondary-icon-tooltip-markup | str | r/w/en | The contents of the tooltip on the secondary icon |
| secondary-icon-tooltip-text | str | r/w/en | The contents of the tooltip on the secondary icon |
| selection-bound | int | r | The position of the opposite end of the selection from the cursor in chars |
| shadow-type | Gtk.ShadowType | d/r/w/en | Which kind of shadow to draw around the entry when has-frame is set deprecated |
| tabs | Pango.TabArray | r/w/en | A list of tabstop locations to apply to the text of the entry |
| text | str | r/w/en | The contents of the entry |
| text-length | int | r | Length of the text currently in the entry |
| truncate-multiline | bool | r/w/en | Whether to truncate multiline pastes to one line. |
| visibility | bool | r/w/en | False displays the “invisible str” instead of the actual text (password mode) |
| width-chars | int | r/w/en | Number of characters to leave space for in the entry |
| xalign | float | r/w/en | The horizontal alignment, from 0 (left) to 1 (right). Reversed for RTL layouts. |
Signals
| Name | Short Description |
|---|---|
| activate | The ::activate signal is emitted when the user hits the Enter key. |
| backspace | The ::backspace signal is a keybinding signal which gets emitted when the user asks for it. |
| copy-clipboard | The ::copy-clipboard signal is a keybinding signal which gets emitted to copy the selection to the clipboard. |
| cut-clipboard | The ::cut-clipboard signal is a keybinding signal which gets emitted to cut the selection to the clipboard. |
| delete-from-cursor | The ::delete-from-cursor signal is a keybinding signal which gets emitted when the user initiates a text deletion. |
| icon-press | The ::icon-press signal is emitted when an activatable icon is clicked. |
| icon-release | The ::icon-release signal is emitted on the button release from a mouse click over an activatable icon. |
| insert-at-cursor | The ::insert-at-cursor signal is a keybinding signal which gets emitted when the user initiates the insertion of a fixed string at the cursor. |
| move-cursor | The ::move-cursor signal is a keybinding signal which gets emitted when the user initiates a cursor movement. |
| paste-clipboard | The ::paste-clipboard signal is a keybinding signal which gets emitted to paste the contents of the clipboard into the text view. |
| populate-popup | The ::populate-popup signal gets emitted before showing the context menu of the entry. |
| preedit-changed | If an input method is used, the typed text will not immediately be committed to the buffer. |
| toggle-overwrite | The ::toggle-overwrite signal is a keybinding signal which gets emitted to toggle the overwrite mode of the entry. |
例子
一
代码:
#!/usr/bin/env python3
# Created by xiaosanyu at 16/6/14
# section 112
TITLE = "Entry"
DESCRIPTION = """
The Gtk.Entry widget is a single line text entry widget.
"""
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject
class EntryWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Entry Demo")
self.set_size_request(200, 100)
self.timeout_id = None
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
self.add(vbox)
self.entry = Gtk.Entry()
self.entry.set_text("Hello World")
vbox.pack_start(self.entry, True, True, 0)
hbox = Gtk.Box(spacing=6)
vbox.pack_start(hbox, True, True, 0)
self.check_editable = Gtk.CheckButton("Editable")
self.check_editable.connect("toggled", self.on_editable_toggled)
self.check_editable.set_active(True)
hbox.pack_start(self.check_editable, True, True, 0)
self.check_visible = Gtk.CheckButton("Visible")
self.check_visible.connect("toggled", self.on_visible_toggled)
self.check_visible.set_active(True)
hbox.pack_start(self.check_visible, True, True, 0)
self.pulse = Gtk.CheckButton("Pulse")
self.pulse.connect("toggled", self.on_pulse_toggled)
self.pulse.set_active(False)
hbox.pack_start(self.pulse, True, True, 0)
self.icon = Gtk.CheckButton("Icon")
self.icon.connect("toggled", self.on_icon_toggled)
self.icon.set_active(False)
hbox.pack_start(self.icon, True, True, 0)
def on_editable_toggled(self, button):
value = button.get_active()
self.entry.set_editable(value)
def on_visible_toggled(self, button):
value = button.get_active()
self.entry.set_visibility(value)
def on_pulse_toggled(self, button):
if button.get_active():
self.entry.set_progress_pulse_step(0.2)
# Call self.do_pulse every 100 ms
self.timeout_id = GObject.timeout_add(100, self.do_pulse, None)
else:
# Don't call self.do_pulse anymore
GObject.source_remove(self.timeout_id)
self.timeout_id = None
self.entry.set_progress_pulse_step(0)
def do_pulse(self, user_data):
self.entry.progress_pulse()
return True
def on_icon_toggled(self, button):
if button.get_active():
icon_name = "system-search-symbolic"
else:
icon_name = None
self.entry.set_icon_from_icon_name(Gtk.EntryIconPosition.PRIMARY,
icon_name)
def main():
win = EntryWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
if __name__ == "__main__":
main()
二.EntryBuffer
代码:
#!/usr/bin/env python3
# section 113
# -*- Mode: Python; py-indent-offset: 4 -*-
# vim: tabstop=4 shiftwidth=4 expandtab
#
# Copyright (C) 2010 Red Hat, Inc., John (J5) Palmieri <johnp@redhat.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
TITLE = "Entry Buffer"
DESCRIPTION = """
Gtk.EntryBuffer provides the text content in a Gtk.Entry.
"""
from gi.repository import Gtk
class EntryBufferApp:
def __init__(self):
self.window = Gtk.Dialog(title='Gtk.EntryBuffer')
self.window.add_buttons(Gtk.STOCK_CLOSE, Gtk.ResponseType.NONE)
self.window.connect('response', self.destroy)
self.window.connect('destroy', lambda x: Gtk.main_quit())
self.window.set_resizable(False)
vbox = Gtk.VBox(homogeneous=False, spacing=0)
self.window.get_content_area().pack_start(vbox, True, True, 0)
vbox.set_border_width(5)
label = Gtk.Label()
label.set_markup('Entries share a buffer. Typing in one is reflected in the other.')
vbox.pack_start(label, False, False, 0)
# create a buffer
buffer = Gtk.EntryBuffer()
#create our first entry
entry = Gtk.Entry(buffer=buffer)
vbox.pack_start(entry, False, False, 0)
# create the second entry
entry = Gtk.Entry(buffer=buffer)
entry.set_visibility(False)
vbox.pack_start(entry, False, False, 0)
self.window.show_all()
def destroy(self, *args):
self.window.destroy()
Gtk.main_quit()
def main():
EntryBufferApp()
Gtk.main()
if __name__ == '__main__':
main()
三.EntryCompletion
代码:
#!/usr/bin/env python3
# section 114
# -*- Mode: Python; py-indent-offset: 4 -*-
# vim: tabstop=4 shiftwidth=4 expandtab
#
# Copyright (C) 2010 Red Hat, Inc., John (J5) Palmieri <johnp@redhat.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA
TITLE = "Entry Completion"
DESCRIPTION = """
Gtk.EntryCompletion provides a mechanism for adding support for
completion in Gtk.Entry.
"""
from gi.repository import Gtk
class EntryCompletionApp:
def __init__(self):
self.window = Gtk.Dialog(title='Gtk.EntryCompletion')
self.window.add_buttons(Gtk.STOCK_CLOSE, Gtk.ResponseType.NONE)
self.window.connect('response', self.destroy)
self.window.connect('destroy', lambda x: Gtk.main_quit())
self.window.set_resizable(False)
vbox = Gtk.VBox(homogeneous=False, spacing=0)
self.window.get_content_area().pack_start(vbox, True, True, 0)
vbox.set_border_width(5)
label = Gtk.Label()
label.set_markup('Completion demo, try writing <b>total</b> or <b>gnome</b> for example.')
vbox.pack_start(label, False, False, 0)
# create our entry
entry = Gtk.Entry()
vbox.pack_start(entry, False, False, 0)
# create the completion object
completion = Gtk.EntryCompletion()
# assign the completion to the entry
entry.set_completion(completion)
# create tree model and use it as the completion model
completion_model = self.create_completion_model()
completion.set_model(completion_model)
completion.set_text_column(0)
self.window.show_all()
@staticmethod
def create_completion_model():
store = Gtk.ListStore(str)
store.append(['GNOME'])
store.append(['total'])
store.append(['totally'])
return store
def destroy(self, *args):
self.window.destroy()
Gtk.main_quit()
def main():
EntryCompletionApp()
Gtk.main()
if __name__ == '__main__':
main()
代码下载地址:http://download.youkuaiyun.com/detail/a87b01c14/9594728

1万+

被折叠的 条评论
为什么被折叠?



