本文整理汇总了Python中label.Label.set_text方法的典型用法代码示例。如果您正苦于以下问题:Python Label.set_text方法的具体用法?Python Label.set_text怎么用?Python Label.set_text使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类label.Label
的用法示例。
在下文中一共展示了Label.set_text方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SpecialistPanel
# 需要导入模块: from label import Label [as 别名]
# 或者: from label.Label import set_text [as 别名]
class SpecialistPanel(Clickable):
def __init__(self, x, y, specialist_instance, selectable=False):
self.surface = Surface((200, 60))
self.specialist = specialist_instance
self.s_type = Label(0, 0, specialist.mapping[specialist_instance.s_type])
self.s_exp = Label(0, 40, "")
self.s_level = Label(0, 20, "")
self.selectable = selectable
self.selected = False
self.x = x
self.y = y
self.w = 200
self.h = 60
def draw(self, screen):
self.surface.fill(0x000000)
pygame.draw.rect(self.surface, 0xb7f315 if self.selected else 0xffffff, Rect(0, 0, 198, 58), 2)
self.s_exp.set_text("Exp: %s/%s" % (self.specialist.experience, self.specialist.level_up_exp))
self.s_level.set_text("Level: %s" % self.specialist.level)
self.s_type.draw(self.surface)
self.s_exp.draw(self.surface)
self.s_level.draw(self.surface)
screen.blit(self.surface, (self.x, self.y))
def is_pressed(self, x, y, button):
if not self.selectable:
return False
if x < self.x:
return False
elif x > self.x + self.w:
return False
elif y < self.y:
return False
elif y > self.y + self.h:
return False
self.selected = not self.selected
return True
示例2: Titlebar
# 需要导入模块: from label import Label [as 别名]
# 或者: from label.Label import set_text [as 别名]
#.........这里部分代码省略.........
self.app_name_align = gtk.Alignment()
self.app_name_align.set(0.5, 0.5, 0.0, 0.0)
self.app_name_align.set_padding(2, 0, 5, 0)
self.app_name_align.add(self.app_name_box)
self.left_box.pack_start(self.app_name_align, False, False)
# Add title.
if title == None:
title_label = ""
else:
title_label = title
self.title_box = Label(
title_label,
text_color=ui_theme.get_color("title_text"),
enable_gaussian=enable_gaussian,
text_x_align=pango.ALIGN_CENTER,
text_size=title_size,
)
self.title_align = gtk.Alignment()
self.title_align.set(0.5, 0.5, 0.0, 0.0)
self.title_align.set_padding(2, 0, 30, 30)
self.title_align.add(self.title_box)
self.left_box.pack_start(self.title_align, True, True)
# Add button box.
self.button_box = gtk.HBox()
self.button_align = gtk.Alignment()
self.button_align.set(1.0, 0.0, 0.0, 0.0)
self.button_align.set_padding(0, 0, 0, 0)
self.button_align.add(self.button_box)
self.right_box = gtk.VBox()
self.right_box.pack_start(self.button_align, False, False)
self.h_layout_box.pack_start(self.right_box, False, False)
# Add theme button.
if "theme" in button_mask:
self.theme_button = ThemeButton()
self.button_box.pack_start(self.theme_button, False, False, 1)
Tooltip.text(self.theme_button, _("Change skin")).show_delay(self.theme_button, 2000)
# Add menu button.
if "menu" in button_mask:
self.menu_button = MenuButton()
self.button_box.pack_start(self.menu_button, False, False, 1)
Tooltip.text(self.menu_button, _("Main menu")).show_delay(self.menu_button, 2000)
# Add min button.
if "min" in button_mask:
self.min_button = MinButton()
self.button_box.pack_start(self.min_button, False, False, 1)
Tooltip.text(self.min_button, _("Minimum")).show_delay(self.min_button, 2000)
# Add max button.
if "max" in button_mask:
self.max_button = MaxButton()
self.button_box.pack_start(self.max_button, False, False, 1)
Tooltip.text(self.max_button, _("Maximize")).show_delay(self.max_button, 2000)
# Add close button.
if "close" in button_mask:
self.close_button = CloseButton()
self.button_box.pack_start(self.close_button, False, False)
Tooltip.text(self.close_button, _("Close")).show_delay(self.close_button, 2000)
# Show.
self.show_all()
def expose_titlebar_separator(self, widget, event):
'''
Expose the separation line between the titlebar and the body of the window.
@param widget: A widget of type Gtk.Widget.
@param event: Not used.
@return: Always return True.
'''
# Init.
cr = widget.window.cairo_create()
rect = widget.allocation
# Draw separator.
cr.set_source_rgba(1, 1, 1, 0.5)
draw_line(cr, rect.x + 1, rect.y + 2, rect.x + rect.width - 1, rect.y + 1)
return True
def change_name(self, name):
'''
Change the name of the application, which is displayed on the center of the title bar.
@param name: New name string that want to set.
'''
self.app_name_box.set_text(name)
def change_title(self, title):
'''
Change the title of the application, which is displayed on the center of the title bar.
@param title: New title string that want to set.
'''
self.title_box.set_text(title)
示例3: ComboBox
# 需要导入模块: from label import Label [as 别名]
# 或者: from label.Label import set_text [as 别名]
#.........这里部分代码省略.........
):
'''
Add items with given index.
@param items: Item list that need add is combo box.
@param select_index: The index of select item, default is 0.
@param pos: Position to insert, except you specified index, items will insert at end by default.
@param clear_first: Whether clear existing items before insert anymore, default is True.
'''
# Init combo widgets.
if clear_first:
self.combo_list.treeview.clear()
combo_items = [ComboTextItem(item[0], item[1]) for item in items]
self.combo_list.treeview.add_items(combo_items, insert_pos=pos)
self.auto_set_size()
self.set_select_index(select_index)
def on_drop_button_press(self, widget, event):
self.combo_list.hover_select_item()
height = self.allocation.height
x, y = self.window.get_root_origin()
if self.combo_list.get_visible():
self.combo_list.hide()
else:
wx, wy = int(event.x), int(event.y)
(offset_x, offset_y) = widget.translate_coordinates(self, 0, 0)
(_, px, py, modifier) = widget.get_display().get_pointer()
droplist_x, droplist_y = px - wx - offset_x - 1, py - wy - offset_y + height - 1
self.combo_list.show((droplist_x, droplist_y), (0, -height))
def on_combo_single_click(self, widget, item, column, x, y):
self.label.set_text(item.title)
self.combo_list.reset_status()
if item:
index = self.combo_list.get_select_index()
self.combo_list.hide_self()
self.emit("item-selected", item.title, item.item_value, index)
def on_focus_in_combo(self, widget, event):
self.focus_flag = True
self.queue_draw()
def on_focus_out_combo(self, widget, event):
self.focus_flag = False
self.queue_draw()
def set_select_index(self, item_index):
'''
Set select item with given index.
@param item_index: The index of selected item.
'''
if 0 <= item_index < len(self.items):
self.combo_list.set_select_index(item_index)
self.label.set_text(self.items[item_index].title)
@property
def items(self):
return self.combo_list.items
def get_item_with_index(self, item_index):
'''
Get item with given index.
示例4: ComboBox
# 需要导入模块: from label import Label [as 别名]
# 或者: from label.Label import set_text [as 别名]
#.........这里部分代码省略.........
def select_prev_item(self):
'''Select preview item.'''
if len(self.droplist.droplist_items) > 0:
prev_index = self.droplist.get_prev_index()
if prev_index != None:
self.droplist.item_select_index = prev_index
self.droplist.active_item()
self.droplist.droplist_items[self.droplist.item_select_index].wrap_droplist_clicked_action()
def select_next_item(self):
'''Select next item.'''
if len(self.droplist.droplist_items) > 0:
next_index = self.droplist.get_next_index()
if next_index != None:
self.droplist.item_select_index = next_index
self.droplist.active_item()
self.droplist.droplist_items[self.droplist.item_select_index].wrap_droplist_clicked_action()
def key_press_combo(self, widget, event):
'''Key press combo.'''
if not self.droplist.get_visible():
key_name = get_keyevent_name(event)
if self.keymap.has_key(key_name):
self.keymap[key_name]()
return True
def set_select_index(self, item_index):
'''Set select index.'''
if 0 <= item_index < len(self.items):
item = self.items[item_index]
if item:
self.select_index = item_index
self.label.set_text(item[0])
def get_item_with_index(self, item_index):
'''Get item with index.'''
if 0 <= item_index < len(self.items):
return self.items[item_index]
else:
return None
def get_current_item(self):
'''Get current item.'''
return self.get_item_with_index(self.select_index)
def key_release_combo(self, widget, event):
'''Handle key release.'''
self.emit("key-release",
self.items[self.select_index][0],
self.items[self.select_index][1],
self.select_index)
def update_select_content(self, droplist, item_content, item_value, item_index):
'''Update select content.'''
self.select_index = item_index
self.label.set_text(item_content)
self.emit("item-selected", item_content, item_value, item_index)
self.grab_focus()
self.queue_draw()
def set_sensitive(self, sensitive):
super(ComboBox, self).set_sensitive(sensitive)