def build(self):
root_widget = BoxLayout(orientation='vertical')
output_label = Label(size_hint_y=1)
button_symbols = ('1', '2', '3', '+',
'4', '5', '6', '-',
'7', '8', '9', '.',
'0', '*', '/', '=')
button_grid = GridLayout(cols=4, size_hint_y=2)
for symbol in button_symbols:
button_grid.add_widget(Button(text=symbol))
clear_button = Button(text='clear', size_hint_y=None,
height=100)
root_widget.add_widget(output_label)
root_widget.add_widget(button_grid)
root_widget.add_widget(clear_button)
return root_widget
python类Label()的实例源码
def show_step_two(self, text_terms, sub_sections_files,
select_sub_section):
"""????????? ????????? ??????? '??? ??????'."""
for sub_section_name in sub_sections_files.keys():
self.sub_sections.add_widget(Label(
text="[color=#2fbfe0][ref={sub_section_name}]"
"{sub_section_name}"
"[/ref]".format(sub_section_name=sub_section_name),
on_ref_press=select_sub_section, markup=True))
self.sub_sections.add_widget(SettingSpacer())
self.scroll_view_two.add_widget(self.sub_sections)
self.step_two.add_widget(RstDocument(text=text_terms))
self.step_two.add_widget(self.scroll_view_two)
self.step_two.disabled = False
self.step_two.collapse = False # ????????? ?????? "??? ??????"
def game(self,instance):
letters=self.letttersinput.text
letters = ",".join(list(letters))
#post data
mydata=[('letters', letters),('order','length'),('pos','beg'),('dic','1'),('table','dict')]
#Encoding
mydata=urllib.urlencode(mydata)
codedPath ='''aHR0cDovL3d3dy50aGV3b3JkZmluZGVyLmNvbS9zY3JhYmJsZS5waHA='''
path=base64.b64decode(codedPath)
req=urllib2.Request(path, mydata)
req.add_header("Content-type", "application/x-www-form-urlencoded")
page=urllib2.urlopen(req).read()
# applying beautifulsoup for parsing
soup = BS(page,"html.parser")
# parsing the div with id
res = soup.find("div", { "id" : "displayresults" })
Con= res.contents[1].contents[1]
line=""
for child in Con.children:
line+= child.string
popup = Popup(title="Result",content=Label(text=line))
popup.open()
def addToBuyList(self, obj):
if(self.pos_system.getBuyList() == None):
content = Label(text = 'You need to start a new list!')
popup = Popup(
title = 'No Buy List',
content = content,
size_hint = (None, None),
size = (400, 100)
)
# open the popup
popup.open()
return
button = Button(text=obj.text, size_hint_y = None, height = 40)
button.bind(on_press = self.removeFromBuyList)
self.a_buylist.add_widget(button)
self.pos_system.getBuyList().addItem(obj.item)
self.updateTotalPrice()
###
def _build_detail_event_box(self, event):
event_layout = BoxLayout(orientation='horizontal')
label_color = rgb_to_kivy(0, 102, 0, 1) if event.evaluation else rgb_to_kivy(255, 0, 0, 1)
# event_eval_text = 'Positive' if event.evaluation else 'Negative'
# event_text = "{} [{}]".format(event.date.strftime("%d/%m/%y %H:%M:%S"), event_eval_text)
event_text = event.date.strftime("%d/%m/%y %H:%M:%S")
event_label = Label(text=event_text, font_size=70, color=label_color, size_hint=(1, 1))
event_rm_button = Button(
text="-",
font_size=50,
size_hint=(.15, 1),
background_normal='',
background_color=rgb_to_kivy(255, 0, 0, 1)
)
handle_rm_with_event = partial(self.handle_rm_event, event)
event_rm_button.bind(on_release=handle_rm_with_event)
event_layout.add_widget(event_label)
event_layout.add_widget(event_rm_button)
return event_layout
def on_pre_enter(self, *args):
# Load relevant transactions
transactions = self.network.hashgraph.get_relevant_transactions()
# Create updated list
def args_converter(row_index, rec):
return {
'height': 60,
'markup': True,
'halign': 'center',
'text': rec['formatted']
}
list_adapter = SimpleListAdapter(data=transactions,
args_converter=args_converter,
cls=Label)
self.list_view = ListView(adapter=list_adapter, size_hint_y=8)
self.ids.box_layout.add_widget(self.list_view, index=1)
def on_pre_enter(self, *args):
members = self.network.hashgraph.known_members.values()
members = [m for m in members if m != self.network.me]
members.sort(key=lambda x: x.formatted_name)
# Create updated list
def args_converter(row_index, rec):
return {
'height': 60,
'markup': True,
'halign': 'center',
'text': repr(members[row_index]),
}
list_adapter = SimpleListAdapter(data=members,
args_converter=args_converter,
cls=Label)
self.list_view = ListView(adapter=list_adapter, size_hint_y=8)
self.ids.box_layout.add_widget(self.list_view, index=1)
def __init__(self, auth_token, **kwargs):
super(CloudCBScreen, self).__init__(**kwargs)
self.header = {'Authorization': "Basic %s" % auth_token}
self.url = SERVER_URI + 'copy-paste/'
self.old_text = Clipboard.paste()
self.cloud_clip = TextInput(text="Fetching...")
layout = BoxLayout(orientation='vertical')
layout.add_widget(Label(text='Cloud Clipboard'))
layout.add_widget(Label(text='Current text on clipboard:'))
layout.add_widget(self.cloud_clip)
layout.add_widget(Button(text='Refresh', on_press=self.download))
layout.add_widget(Label(text='Earlier text on your clipboard:'))
layout.add_widget(TextInput(text=self.old_text))
layout.add_widget(Button(text='Update Cloud Clipboard with this text', on_press=self.upload))
self.add_widget(layout)
self.download()
def new_label(self):
a_caption = 'Label' + '{:02d}'.format(self.count_objs)
self.count_objs += 1
mypage.unilabel((40, 240, 80, 20, a_caption))
a_label = mypage.unilabels [-1]
a_label.size_hint=(None,None)
a_label.height = 20;
if mypage.kivy:
a_label.background_color = a_label.color
a_label.bind(on_touch_down=self.touch_down)
a_label.bind(on_touch_move=self.touch_move)
else:
a_label.touch_enabled = False
a_label.pos = (a_label.x, a_label.y)
a_label.color = a_label.background_color
self.new_objs.append(a_label)
def new_label(self):
a_caption = 'Label' + '{:02d}'.format(self.count_objs)
self.count_objs += 1
mypage.unilabel((40, 240, 80, 20, a_caption))
a_label = mypage.unilabels [-1]
a_label.size_hint=(None,None)
a_label.height = 20;
if mypage.kivy:
a_label.background_color = a_label.color
a_label.bind(on_touch_down=self.touch_down)
a_label.bind(on_touch_move=self.touch_move)
else:
a_label.touch_enabled = False
a_label.pos = (a_label.x, a_label.y)
a_label.color = a_label.background_color
self.new_objs.append(a_label)
def set_info(self, data_to_write, x_hint_list, num_rows_to_add = 3):
#Takes in the file data, and updates the Grid to represent
#and indicate the files that are loaded with their metadata.
if len(data_to_write) != self.cols:
print('--Set info: Data mismatch error.')
popup = Popup(title='Grid Error 02',
content=Label(text = 'There was a problem in updating the grid.'),
size_hint = (0.3, 0.3))
popup.open()
else:
threshold = 3
#If < threshold available rows left, add more
if self._avail < threshold:
self.create_grid(x_hint_list, num_rows_to_add)
length = len(self.children)
next_row = self.find_next_row()
end = length - (next_row * self.cols)
start = end - self.cols
for i, widget in enumerate(reversed(self.children[start:end])):
#strip text primarily for title and artist, so shorten
#doesn't take into account the trailing whitespace
widget.text = data_to_write[i].strip()
self._avail -= 1
def load_audio_file(self, path):
from kivy.core.audio import SoundLoader
sound = SoundLoader.load(path)
self._sound = sound
if sound:
update_bar_schedule = Clock.schedule_interval(self.update_bar, 1)
self._update_bar_schedule = update_bar_schedule
self.ids.p_bar.max = sound.length
sound.volume = self.ids.volume_slider.value
sound.play()
else:
print('Cannot play the file %s.' % path)
error_msg = 'Cannot play the file %s.' % (path) if path else 'No file selected.'
popup = Popup(title='Audio Error.',
content=Label(text= error_msg),
size_hint = (0.3, 0.3))
popup.open()
def build(self):
floater = 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})
floater.add_widget(logo)
floater.add_widget(spiderman)
floater.add_widget(enter)
return floater
def __init__(self, **kwargs): # inicializace
super(PartylineScreen, self).__init__(**kwargs)
self.root.insertStrings.append((self, "STR_PARTYLINE"))
self.input = TextInput(size_hint=(.8, .07), pos_hint={'x':.08, 'y':.024})
self.output = Label(markup=True, font_name='font/Roboto-Regular.ttf', font_size='16dp', size_hint_y = None)
self.SLayout = GridLayout(size_hint_y = None, cols=1, spacing=0)
self.SLayout.bind(minimum_height=self.SLayout.setter('height'))
self.scroll = ScrollView(size_hint=(1,.9), pos_hint={'center_x': .58, 'y': .125}, scroll_timeout=10000)
self.scroll.do_scroll_x = False
self.scroll.add_widget(self.SLayout)
self.SLayout.add_widget(self.output)
self.layout = RelativeLayout(size_hint=(.75, .83), pos_hint={'center_x': .437, 'y': .02})
self.send = DelButton(color=(1,1,1,0), text='SEND', size_hint=(None, .1), pos_hint={'x':.88, 'y':.022}, background_normal='crop/icons/send.png', background_down='crop/icons/send.png')
self.send.bind(on_press=self.sendMsg)
self.input.bind(focus=self.on_focus)
self.layout.content.add_widget(self.scroll)
self.layout.content.add_widget(self.input)
self.layout.content.add_widget(self.send)
self.add_widget(self.layout)
if self.root.onAndroid():
self.LayouFocusOn = Animation(size_hint_y=.5, pos_hint={'center_x': .437, 'y': .38}, duration=.2)
self.LayouFocusOut = Animation(size_hint_y=.83, pos_hint={'center_x': .437, 'y': .02}, duration=.2)
def on_release(self):
label = Label(size_hint_y=None,size_hint_x=None)
label.bind(texture_size=label.setter('size'))
fob = open("help.txt")
label.text = fob.read()
fob.close()
content = ScrollView(size_hint=(1,1))
content.add_widget(label)
popup = Popup(title="Help",content=content,size_hint=(0.6,0.6)).open()
def build(self):
# Resource tree creation
root = resource.CoAPResource()
well_known = resource.CoAPResource()
root.putChild('.well-known', well_known)
core = CoreResource(root)
well_known.putChild('core', core)
counter = MOTDResource(self, 0)
root.putChild('motd', counter)
endpoint = resource.Endpoint(root)
reactor.listenUDP(coap.COAP_PORT, coap.Coap(endpoint))
# Kivy screen initialization
self.label = Label(text="")
self.display_counter(0)
self.messagebox = TextInput(size_hint_y=.1, multiline=False)
self.messagebox.text = "Message of the day"
self.layout = BoxLayout(orientation='vertical', padding=10)
self.layout.add_widget(self.label)
self.layout.add_widget(self.messagebox)
return self.layout
def on_enter(self):
# when we add children to the grid layout, its size doesn't change at
# all. we need to ensure that the height will be the minimum required
# to contain all the childs. (otherwise, we'll child outside the
# bounding box of the childs)
self.ids.audioSidebar.bind(minimum_height=self.ids.audioSidebar.setter('height'))
progress_bar = ProgressBar( value=0, size_hint= (0.5, None))
label = Label(text = 'Waiting', size_hint= (0.32, None))
label2 = Label(text='N/A%', size_hint= (0.18, None))
self.ids.audioSidebar.add_widget(label2)
self.ids.audioSidebar.add_widget(progress_bar)
self.ids.audioSidebar.add_widget(label)
self.app.chat_client = HQCWSClient(self.app.config)
self.app.chat_client.app = self.app
self.app.chat_client.config = self.app.config
# self.app.chat_client.send_sync(constants.SYN)
# create a scroll view, with a size < size of the grid
# root = ScrollView(size_hint=(None, None), size=(310, 460),
# pos_hint={'center_x': .5, 'center_y': .5}, do_scroll_x=False)
# root.add_widget(audioClipLayout)
# self.ids.audioSidebar.add_widget(root)
def on_enter(self):
if self.app.config.get('ChatSettings', 'role') == "PRODUCER":
files = self.app.get_own_state()['requested_files']
for file in files:
label = Label(text=file, size_hint=(1 / len(files), None))
self.ids.filelayout.add_widget(label)
elif self.app.config.get('ChatSettings', 'role') == "ARTIST":
files = self.app.get_own_state()['requested_files']
if files:
header_label = Label(text="Files being sent", size_hint=(1 / len(files), None), color=[0, 0, 0, 1])
self.ids.filelayout.add_widget(header_label)
for file in files:
full_path = self.app.config.get_file_name(self.app.session_name, file)
self.app.chat_client.send_file(full_path)
label = Label(text=file, size_hint=(1 / len(files), None), color=[0, 0, 0, 1])
self.ids.filelayout.add_widget(label)
else:
pass
def update_dialog(self, cur_build, upd_build):
popup = Popup(title='Update', content=ScrollView(), size_hint=(0.8,None), height=cm(5))
grid = GridLayout(cols=1, spacing=0, size_hint_y=None)
grid.bind(minimum_height= grid.setter('height'))
con = StackLayout()
grid.add_widget(con)
popup.content.add_widget(grid)
lbl1 = Label(text='Current build is %s' % (cur_build), size_hint_y=None, height=cm(1))
lbl2 = Label(text='Build %s available' % (upd_build), size_hint_y=None, height=cm(1))
btn1 = Button(text='Cancel', size_hint=(0.5, None), height=cm(1))
btn2 = Button(text='Update', size_hint=(0.5, None), height=cm(1))
btn1.bind(on_release=popup.dismiss)
btn2.bind(on_release=lambda x: {self.update(), popup.dismiss()})
for x in (lbl1, lbl2, btn1, btn2):
con.add_widget(x)
popup.open()
def update_dialog(self, cur_build, upd_build):
popup = Popup(title='Update', content=ScrollView(), size_hint=(0.8,None), height=cm(5))
grid = GridLayout(cols=1, spacing=0, size_hint_y=None)
grid.bind(minimum_height= grid.setter('height'))
con = StackLayout()
grid.add_widget(con)
popup.content.add_widget(grid)
lbl1 = Label(text='Current build is %s' % (cur_build), size_hint_y=None, height=cm(1))
lbl2 = Label(text='Build %s available' % (upd_build), size_hint_y=None, height=cm(1))
btn1 = Button(text='Cancel', size_hint=(0.5, None), height=cm(1))
btn2 = Button(text='Update', size_hint=(0.5, None), height=cm(1))
btn1.bind(on_release=popup.dismiss)
btn2.bind(on_release=lambda x: {self.update(), popup.dismiss()})
for x in (lbl1, lbl2, btn1, btn2):
con.add_widget(x)
popup.open()
def reg(args, n, p):
if n == "Nickname.." or n == "":
p = Popup(title='Login Error', content=Label(text="Digite seu apelido!", color=(1,0,0,1)),size_hint=(.6, .2))
p.open()
elif p == "Password.." or p == "":
p = Popup(title='Login Error', content=Label(text="Digite sua senha!", color=(1,0,0,1)),size_hint=(.6, .2))
p.open()
else:
# Tratando dados..
name = addslashes(n)
pswd = addslashes(p)
sql = "select * from users where nickname = '"+name+"'"
rows = cur.execute(sql)
if rows > 0:
p = Popup(title='Login Error', content=Label(text="Este apelido esta em uso!", color=(1,0,0,1)),size_hint=(.6, .2))
p.open()
else:
sql = "insert into users (nickname, passwd, level, photo, online) values ('"+name+"', '"+pswd+"', 'Usuario', default, '0')"
cur.execute(sql)
con.commit()
p = Popup(title='Cadastramento Concluído', content=Label(text=name+", Cadastrado com sucesso!", color=(0,1,0,1)),size_hint=(.6, .2))
p.open()
def do_login(self, loginText, passwordText):
a = SnapDB()
val = a.checkLogin(nickname=loginText, password=passwordText)
userID = val[1]
if val[1] != None:
a = SnapDB()
a.getUserData(userID)
popup = Popup(title='Hola', content=Label(text='Hi '+localFiles.getLocalUserInfo()[2].split(" ")[0]+', happy snapchatting!'), size_hint=(None, None), size=(350, 200))
popup.open()
self.manager.transition = SlideTransition(direction="left")
self.manager.current = 'connected'
else:
popup = Popup(title='Error', content=Label(text='The password or username are incorrect. Try again.'), size_hint=(None, None), size=(350, 200))
popup.open()
app = App.get_running_app()
app.config.read(app.get_application_config())
app.config.write()
def checkSnapInbox(self):
try:
print("Looking for snaps...")
a = Snap()
namesFound = a.getImageName(localFiles.getLocalUserInfo()[0])[0]
idsFound = a.getImageName(localFiles.getLocalUserInfo()[0])[1]
if len(namesFound) == 0:
popup = Popup(title='Oops!', content=Label(text='There are no new snaps for you, '+localFiles.getLocalUserInfo()[2].split(" ")[0]), size_hint=(None, None), size=(350, 200))
popup.open()
else:
for x in range(len(namesFound)):
img = str(namesFound[x]).strip()
ImageFunctions.showImg(img)
a.updateSnapStatus(localFiles.getLocalUserInfo()[0])
except:
print("ERROR")
def desktop_warning(self):
layout = BoxLayout(orientation='vertical')
layout.add_widget(Label(text='KivMob will not display ads on ' +\
'nonmobile platforms. You must build an ' +\
'Android project to demo ads. (iOS not yet ' +\
'supported)',
size_hint_y=1,
text_size=(250, None),
halign='left',
valign='middle'))
button_layout = BoxLayout()
button1=Button(text="Open Build Steps", size_hint=(0.8, 0.2))
button1.bind(on_release = lambda x :
webbrowser.open("https://www.google.com"))
button_layout.add_widget(button1)
button2=Button(text="Close", size_hint=(0.8, 0.2))
button2.bind(on_release = lambda x : popup.dismiss())
button_layout.add_widget(button2)
layout.add_widget(button_layout)
popup = Popup(title='KivMob Demo Alert',
content=layout,
size_hint=(0.9, 0.9))
popup.open()
def interstitial_warning(self):
layout = BoxLayout(orientation='vertical')
layout.add_widget(Label(text="Ad has not loaded. " +\
"Wait a few seconds and then " +\
"try again.",
size_hint_y=1,
text_size=(250, None),
halign='left',
valign='middle'))
button_layout = BoxLayout()
close=Button(text="Close", size_hint=(0.8, 0.2))
close.bind(on_release = lambda x : popup.dismiss())
button_layout.add_widget(close)
layout.add_widget(button_layout)
popup = Popup(title='KivMob Demo Alert',
content=layout,
size_hint=(0.9, 0.9))
popup.open()
def create_menu_buttons(self):
"""??????? ?????? ? ??????? ????."""
name_path_buttons_menu = {
"JUNK FILES": "Data/Images/clean_cache.png",
"MEMORY BOOST": "Data/Images/clean_memory.png",
"APP MANAGER": "Data/Images/clean_apk.png",
"SECURITY & PRIVACY": "Data/Images/clean_privacy.png"}
for name_button in name_path_buttons_menu.keys():
item_box = BoxLayout(orientation="vertical")
item_label = Label(text=name_button, color=[.1, .1, .1, 1])
item_button = \
ImageButton(source=name_path_buttons_menu[name_button],
id=name_button, on_press=self.events_callback)
item_box.add_widget(item_button)
item_box.add_widget(item_label)
self.ids.body_buttons_menu.add_widget(item_box)
def __init__(self, **kvargs):
super(AboutDialog, self).__init__(**kvargs)
if self.flag:
self.background_box_content = [0.0, 0.0, 0.0, 1.0]
box_content = self.ids.box_content
height, avatar_size_hint = (60, (.05, .9)) if not self.flag \
else (120, (.1, 1))
self.ids.logo.size_hint = avatar_size_hint
self.ids.box_logo_and_title.height = height
# ????????? ??????????.
for info_string in self.info_program:
if info_string == "":
box_content.add_widget(SettingSpacer())
continue
info_string = \
Label(text=info_string, size_hint_y=None,
font_size=self.base_font_size, markup=True,
on_ref_press=self.events_callback)
info_string.bind(size=lambda *args: self._update_label_size(args))
box_content.add_widget(info_string)
if not self.flag:
self.body_message = Popup(
underline_color=self.underline_color, content=self,
title=self.title_message,
size_hint=(self.user_size_hint[0], self.user_size_hint[1]),
pos_hint={"center_x": .5, "center_y": .5},
background=self.background_image,
on_dismiss=self.dismiss_callback)
self.body_message.open()
else:
refs = Label(text=self.refs, markup=True, size_hint=(1, .1))
refs.bind(on_ref_press=self.events_callback)
self.add_widget(refs)
def __init__(self, **kvargs):
super(ProgressLoad, self).__init__(**kvargs)
self.orientation = "vertical"
self.padding = 20
self.KProgress = kvargs.get("KProgress")
self.label_one = Label(text="", size_hint=(1, .1), markup=True)
self.label_two = Label(text="", size_hint=(1, .1), markup=True)
self.progress_load = self.KProgress()
self.button_cancel = \
Button(text="Cancel", on_press=self.events_callback,
size_hint=(1, .2))
self.label_one.bind(
size=lambda *args: self._update_text_size(args))
self.label_two.bind(
size=lambda *args: self._update_text_size(args))
self.add_widget(self.label_one)
self.add_widget(self.label_two)
self.add_widget(Widget(size_hint=(None, .02)))
self.add_widget(SettingSpacer())
self.add_widget(Widget(size_hint=(None, .02)))
self.add_widget(self.progress_load)
self.add_widget(Widget(size_hint=(None, .3)))
self.add_widget(SettingSpacer())
self.add_widget(Widget(size_hint=(None, .02)))
self.add_widget(self.button_cancel)
self.progress_load.min = 0
self.progress_load.max = 100
self.progress_load.bar_value = 0
self.progress_load.spacing_widget = 2
self.progress_load.height_widget = 1
self.progress_load.color = "#ff7f32"
self.progress_load.background_color = "#2fbfe0"
self.progress_load.border_color = "#2fbfe0"
def build(self):
return Label(text='Hello World')
def __init__(self, **kwargs):
super(PopupLabel, self).__init__(**kwargs)
scroller = AppScrollView()
lbl = Label(
size_hint_y=None, text_size=(scroller.width, None), text=self.text)
scroller.bind(size=self._update_text_size)
lbl.bind(texture_size=self._update_text_widget_size)
scroller.add_widget(lbl)
self.content, self.lbl = scroller, lbl