本文整理匯總了Python中widgets.Widget.add_widget方法的典型用法代碼示例。如果您正苦於以下問題:Python Widget.add_widget方法的具體用法?Python Widget.add_widget怎麽用?Python Widget.add_widget使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類widgets.Widget
的用法示例。
在下文中一共展示了Widget.add_widget方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ask_tricks
# 需要導入模塊: from widgets import Widget [as 別名]
# 或者: from widgets.Widget import add_widget [as 別名]
def ask_tricks(self, n):
"""
Ask the user for the number of tricks.
:param n: the maximum number of tricks
"""
# Create the container with the fade in effect.
container = Widget((self.screen.get_width()/2-200, 100), (400, self.screen.get_height()-120), 40)
container.opacity = 0
container.add_action(actions.FadeInAction(0.5))
self._ask_tricks_widget = container
self._background_widget.add_widget(container)
# Create the question text.
text_w = special_widgets.warning_widget((0, 0), (400, 60), "How many tricks do you make?", self._font,
close_on_click=False)
text_w.visible = True
container.add_widget(text_w)
# Create the numbers.
class ChooseHandler(object):
def __init__(self, view, nn):
self._view = view
self._n = nn
def __call__(self, x, y):
self._view._handle_say_tricks(self._n)
for i in xrange(n+1):
size = (50, 50)
pos = ((i % 6) * (size[0]+20), 80 + (i/6) * (size[1] + 20))
w = special_widgets.warning_widget(pos, size, str(i), self._font, close_on_click=False)
w.visible = True
w.handle_clicked = ChooseHandler(self, i)
container.add_widget(w)
示例2: _create_widgets
# 需要導入模塊: from widgets import Widget [as 別名]
# 或者: from widgets.Widget import add_widget [as 別名]
def _create_widgets(self):
"""
Create the widgets and return the one that contains them all.
:return: the background widget
"""
# Create the background widget.
bg = self._rm.get_image(BACKGROUND_IMAGE, self.screen.get_size())
bg_widget = ImageWidget((0, 0), self.screen.get_size(), -1, bg)
# Create the container for the input widgets.
x = (self.screen.get_width() - INPUT_WIDTH - INPUT_PADDING[1] - INPUT_PADDING[3]) / 2
y = self.screen.get_height() / 2
w = INPUT_WIDTH + INPUT_PADDING[1] + INPUT_PADDING[3]
h = self.screen.get_height() - y
input_container = Widget((x, y), (w, h), 0)
bg_widget.add_widget(input_container)
# Create the input widgets.
username_input = TextInput(
(0, 0),
INPUT_WIDTH,
0,
self._font,
padding=INPUT_PADDING,
color=INPUT_FORE_COLOR,
fill=INPUT_FILL_COLOR,
default_text="username",
default_font=self._default_font,
)
host_input = copy.copy(username_input)
host_input.default_text = "host"
host_input.position = (0, INPUT_OFFSET)
port_input = copy.copy(username_input)
port_input.default_text = "port"
port_input.position = (0, 2 * INPUT_OFFSET)
input_container.add_widget(username_input)
input_container.add_widget(host_input)
input_container.add_widget(port_input)
self._text_inputs = {"username": username_input, "host": host_input, "port": port_input}
# Create the button widget.
btn = special_widgets.simple_button((0, 3 * INPUT_OFFSET), (w, 100), "Login", self._font)
def btn_clicked(x, y):
self._ev_manager.post(events.LoginRequestedEvent())
btn.handle_clicked = btn_clicked
input_container.add_widget(btn)
# Create the connection failed warning.
self._connection_failed_warning = special_widgets.warning_widget(
None, (400, 100), "Connection failed", self._font, screen_size=self.screen.get_size()
)
bg_widget.add_widget(self._connection_failed_warning)
self._username_taken_warning = special_widgets.warning_widget(
None, (400, 100), "Username already taken", self._font, screen_size=self.screen.get_size()
)
bg_widget.add_widget(self._username_taken_warning)
return bg_widget