def build(self):
return Button(text="Press me!", on_release=self.show_palette)
python类Button()的实例源码
def build(self):
return Button(text="Press me!", on_release=self.show_setting)
def build(self):
button = Button(text="Press me!")
button.bind(on_release=self.show_dialog)
return button
def build(self):
return Button(text='Hello World')
def __init__(self):
super(WallEEGApp, self).__init__()
self.user = User()
self.graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5,
x_ticks_major=25, y_ticks_major=0.001,
y_grid_label=True, x_grid_label=True, padding=5,
x_grid=True, y_grid=True, xmin=-0, xmax=100,
ymin=-0.1,
ymax=0.1)
self.plot = MeshLinePlot(color=[1, 0, 0, 1])
self.counter = 0
# def build(self):
# return InSenseView()
# def build(self):
# g = Gui()
# point_collection = PointsCollection(1000, 1000, 0, 100, 0, 100)
#
# for i in range(100):
# x_coord = random.randint(
# point_collection.x_min, point_collection.x_max)
# y_coord = random.randint(
# point_collection.y_min, point_collection.y_max)
#
# point_collection.add_point_vals(x_coord, y_coord)
#
# for point in point_collection.points_list:
# g.grid.add_widget(point)
# # for i in range(24):
# # g.grid.add_widget(Button(text='test'))
#
# return g
def __init__(self,**kwargs):
super(WordUI, self).__init__(**kwargs)
self.cols=2
#adding text label
self.add_widget(Label(text="insert the words:"))
#adding text Input
self.letttersinput = TextInput(multiline=False)
self.add_widget(self.letttersinput)
#adding the action button
self.add_widget(Button(text="Generate", on_press=self.game , pos=(50, 100)))
def __init__(self, **kwargs):
super(LoginScreen, self).__init__(**kwargs)
'''self.orientation = 'vertical'
###
self.grid = GridLayout()
self.grid.cols = 2
self.grid.add_widget(Label(text='User Name'))
self.grid.username = TextInput(multiline=False)
self.grid.add_widget(self.grid.username)
self.grid.add_widget(Label(text='password'))
self.grid.password = TextInput(multiline=False)
self.grid.add_widget(self.grid.password)
###
self.options = BoxLayout()
self.options.size_hint_y = 0.5
self.options.bt_cancel = Button(text='Cancel')
self.options.add_widget(self.options.bt_cancel)
self.options.bt_login = Button(text='Login')
self.options.bt_login.bind(on_press=self.bt_login_clicked)
self.options.add_widget(self.options.bt_login)
###
self.add_widget(self.grid)
self.add_widget(self.options)'''
###
def loadMainWindow(self, obj = None):
self.atual_menu = 0
op_n = 1
mainOptions = [APPERTIZERS_NAME, MEAT_NAME, FISH_NAME, VEGAN_NAME, DRINKS_NAME, DESSERT_NAME]
self.a_articles.clear_widgets()
for op in mainOptions:
button = Button(text=op)
button.bind(on_press=self.openNewMenu)
op_n = op_n + 1
self.a_articles.add_widget(button)
for a in range(op_n-1, 9):
self.a_articles.add_widget(Label(text=''))
self.bt_next.enabled = False
self.bt_previous.enabled = False
if(self.pos_system.getBuyList() == None):
self.bt_newlist.enabled = True
self.bt_clearlist.enabled = False
self.bt_finishlist.enabled = False
self.menu_page = 0
###
def loadBarOptions(self):
self.a_baroptions.add_widget(Button(text='Close Session', on_press=self.userLogout))
self.bt_newlist = ButtonEx(text = 'New List', on_press=self.startNewBuyList)
self.a_baroptions.add_widget(self.bt_newlist)
self.bt_clearlist = ButtonEx(text = 'Clear List', on_press=self.clearBuyList)
self.a_baroptions.add_widget(self.bt_clearlist)
self.bt_finishlist = ButtonEx(text = 'Finish List', on_press=self.finishBuyList)
self.a_baroptions.add_widget(self.bt_finishlist)
self.bt_next = ButtonEx(text = 'Next', on_press = self.changePage)
self.a_baroptions.add_widget(self.bt_next)
self.bt_previous = ButtonEx(text = 'Previous', on_press = self.changePage)
self.a_baroptions.add_widget(self.bt_previous)
self.a_baroptions.add_widget(Button(text = 'Menu', on_press = self.loadMainWindow))
###
def openNewMenu(self, obj):
op_n = 1
total_rows = 0
if obj != self.bt_next and obj != self.bt_previous:
self.menu_type = obj.text.lower()
cursor = self.database.loadArticles(self.menu_type, self.menu_page)
self.a_articles.clear_widgets()
for row in cursor:
total_rows = total_rows + 1
if(total_rows > 9) : break
button = Button(text=row[1])
button.bind(on_press=self.addToBuyList)
button.item = Item(id_p = row[0], name = row[1], price = row[2], tax = 0.2)
op_n = op_n + 1
self.a_articles.add_widget(button)
for a in range(op_n-1, 9):
self.a_articles.add_widget(Label(text=''))
if(total_rows > 9):
self.bt_next.enabled = True
else:
self.bt_next.enabled = False
if(self.menu_page > 0):
self.bt_previous.enabled = True
else:
self.bt_previous.enabled = False
###
def _filter_layout(self):
filter_box = BoxLayout(orientation='vertical', spacing=50)
dropdown = DropDown()
for filter_type in FILTERS.keys():
filter_button = Button(
text=filter_type,
font_size=30,
background_normal='',
background_color=rgb_to_kivy(239, 93, 5, 1),
size_hint_y=None,
height=130
)
handle_filter_button_with_dropdown = partial(self.handle_filter_button, dropdown)
filter_button.bind(on_release=handle_filter_button_with_dropdown)
dropdown.add_widget(filter_button)
filter_dropdown_btn = Button(
text=ALL_FILTER,
font_size=30,
size_hint=(1, 1),
background_normal='',
background_color=rgb_to_kivy(239, 93, 5, 1)
)
filter_dropdown_btn.bind(on_release=dropdown.open)
dropdown.bind(on_select=lambda instance, x: setattr(filter_dropdown_btn, 'text', x))
filter_box.add_widget(filter_dropdown_btn)
return filter_box
def _build_main_box(self):
main_box = BoxLayout(orientation='vertical')
back_button = Button(
text="Back",
font_size=30,
size_hint=(0.15, 0.15),
)
back_button.bind(on_release=self.handle_back_button)
main_box.add_widget(back_button)
main_box.add_widget(self._build_event_list())
return main_box
def build(self):
return Button(text='Hello World')
def __init__(self, **kwargs):
super(LoginScreen, self).__init__(**kwargs)
self.username_w = TextInput(multiline=False)
self.password_w = TextInput(password=True, multiline=False)
self.login_btn = Button(text='Login')
self.login_btn.bind(on_press=self.login)
layout = GridLayout()
layout.cols = 2
layout.add_widget(Label(text='Username'))
layout.add_widget(self.username_w)
layout.add_widget(Label(text='Password'))
layout.add_widget(self.password_w)
layout.add_widget(self.login_btn)
self.add_widget(layout)
def unibutton(self, params):
self.unibuttons.append([])
if len(params) == 6:
function = params[5]
else:
function = nofunction
if self.kivy:
from kivy.uix.button import Button
self.unibuttons[len(self.unibuttons) - 1] = Button(
text = params[4],
size_hint_y = None,
size_hint_x = None,
height = params[3] * self.yratio,
width = params[2] * self.xratio,
font_size = 17.5 * self.yratio,
pos = (params[0] * self.xratio, params[1] * self.yratio),
on_press = function )
self.root.add_widget(self.unibuttons[len(self.unibuttons) - 1])
else:
import ui
self.unibuttons[len(self.unibuttons) - 1] = ui.Button(frame= \
(params[0] * self.xratio, (600 - params[1] - \
params[3]) * self.yratio, \
params[2] * self.xratio, params[3] * self.yratio), \
title = params[4])
self.unibuttons[len(self.unibuttons) - 1].background_color \
= (0.4,0.4,0.4)
self.unibuttons[len(self.unibuttons) - 1].action = function
self.unibuttons[len(self.unibuttons) - 1].height = params[3] * \
self.xratio
self.unibuttons[len(self.unibuttons) - 1].width = params[2] * \
self.yratio
self.unibuttons[len(self.unibuttons) - 1].tint_color = 'white'
self.root.add_subview(self.unibuttons[len(self.unibuttons) - 1])
def unibutton(self, params):
self.unibuttons.append([])
if len(params) == 6:
function = params[5]
else:
function = nofunction
if self.kivy:
from kivy.uix.button import Button
self.unibuttons[len(self.unibuttons) - 1] = Button(
text = params[4],
size_hint_y = None,
size_hint_x = None,
height = params[3] * self.yratio,
width = params[2] * self.xratio,
font_size = 17.5 * self.yratio,
pos = (params[0] * self.xratio, params[1] * self.yratio),
on_press = function )
self.root.add_widget(self.unibuttons[len(self.unibuttons) - 1])
else:
import ui
self.unibuttons[len(self.unibuttons) - 1] = ui.Button(frame= \
(params[0] * self.xratio, (600 - params[1] - \
params[3]) * self.yratio, \
params[2] * self.xratio, params[3] * self.yratio), \
title = params[4])
self.unibuttons[len(self.unibuttons) - 1].background_color \
= (0.4,0.4,0.4)
self.unibuttons[len(self.unibuttons) - 1].action = function
self.unibuttons[len(self.unibuttons) - 1].height = params[3] * \
self.xratio
self.unibuttons[len(self.unibuttons) - 1].width = params[2] * \
self.yratio
self.unibuttons[len(self.unibuttons) - 1].tint_color = 'white'
self.unibuttons[len(self.unibuttons) - 1].font = ('<system>', \
17.5 * self.yratio)
self.root.add_subview(self.unibuttons[len(self.unibuttons) - 1])
def unibutton(self, params):
self.unibuttons.append([])
if len(params) == 6:
function = params[5]
else:
function = nofunction
if self.kivy:
from kivy.uix.button import Button
self.unibuttons[len(self.unibuttons) - 1] = Button(
text = params[4],
size_hint_y = None,
size_hint_x = None,
height = params[3] * self.yratio,
width = params[2] * self.xratio,
font_size = 17.5 * self.yratio,
pos = (params[0] * self.xratio, params[1] * self.yratio),
on_press = function )
self.root.add_widget(self.unibuttons[len(self.unibuttons) - 1])
else:
import ui
self.unibuttons[len(self.unibuttons) - 1] = ui.Button(frame= \
(params[0] * self.xratio, (600 - params[1] - \
params[3]) * self.yratio, \
params[2] * self.xratio, params[3] * self.yratio), \
title = params[4])
self.unibuttons[len(self.unibuttons) - 1].background_color \
= (0.4,0.4,0.4)
self.unibuttons[len(self.unibuttons) - 1].action = function
self.unibuttons[len(self.unibuttons) - 1].height = params[3] * \
self.xratio
self.unibuttons[len(self.unibuttons) - 1].width = params[2] * \
self.yratio
self.unibuttons[len(self.unibuttons) - 1].tint_color = 'white'
self.unibuttons[len(self.unibuttons) - 1].font = ('<system>', \
17.5 * self.yratio)
self.root.add_subview(self.unibuttons[len(self.unibuttons) - 1])
def create_grid(self, x_hint_list, rows_to_create):
#x_hint_list is a list of ints, relating to the intended
#width of each column in the grid.
for row in range(rows_to_create):
for x_hint in x_hint_list:
grid_button = Button(text = '', valign = 'middle', shorten = True, size_hint_y = None,
height = 30, size_hint_x = x_hint, background_color = cfg_primary_neutral,
background_normal = '', color = cfg_primary_dark)
grid_button.bind(size=grid_button.setter('text_size'))
grid_button.bind(on_touch_down=self.button_press)
self.add_widget(grid_button)
self._avail += rows_to_create
def __init__(self, **kwargs):
super(DisplayManeuver, self).__init__(**kwargs)
self.maneuvers = {"apoapsis" : "120000",
"periapsis": "100000"}
self.dropdown = DropDown()
self.input = FloatInput(size=(200, 30),
multiline=False,
size_hint=(None, None))
for m in self.maneuvers.keys():
btn = Button(text=m, size_hint_y=None, height=30)
# Pass the text of the button as the data of the selection.
btn.bind(on_release=lambda btn: self.dropdown.select(btn.text))
self.dropdown.add_widget(btn)
self.mainbutton = Button(text='Maneuver',
size=(160, 50),
size_hint=(None, None))
self.mainbutton.bind(on_release=self.dropdown.open)
def dropdown_action(instance, m):
self.input.text = self.maneuvers[m]
self.mainbutton.text = m
self.dropdown.bind(on_select=dropdown_action)
self.go_button = Button(text='Go',
size=(160, 50),
size_hint=(None, None))
self.go_button.bind(on_press=self.go)
self.add_widget(self.mainbutton)
self.add_widget(self.input)
self.add_widget(self.go_button)
def build(self):
mainpage = FloatLayout()
logo = Image(source='AutoPen.png', pos_hint={'center_x': 0.5, 'center_y': .6})
spiderman = Label(
text='[size=24][i]With Great Power comes Great Responsibility[/i][/size]',
markup=True,
pos_hint={'center_x': 0.5, 'center_y': .2})
enter = Button(text='enter', size_hint=(0.2,0.1), pos_hint={'center_x': 0.5, 'center_y': .1})
mainpage.add_widget(logo)
mainpage.add_widget(spiderman)
mainpage.add_widget(enter)
return mainpage
#layout.add_widget(MainToolsScreen())