本文整理汇总了Python中kivy.uix.image.Image.add_widget方法的典型用法代码示例。如果您正苦于以下问题:Python Image.add_widget方法的具体用法?Python Image.add_widget怎么用?Python Image.add_widget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.uix.image.Image
的用法示例。
在下文中一共展示了Image.add_widget方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadScores
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import add_widget [as 别名]
def loadScores(self, obj):
app = self
self.clear_widgets()
helpimg = Image(source = 'assets/help.jpg')
back = Button(text = "BACK",font_size = 25)
helpimg.add_widget(back)
self.add_widget(helpimg)
def backfn(obj):
self.__init__()
back.bind(on_press = backfn)
return self
示例2: loadhelp
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import add_widget [as 别名]
def loadhelp(self,obj):
app = self
x,y = 1280,736
self.root.clear_widgets()
helpimg = Image(source = 'assets/help.jpg')
back = Button(text = "Got it. Lets Play!",font_size = 25,pos = (x-x*3/8,y/10),size=(x/4,y/8))
helpimg.add_widget(back)
self.root.add_widget(helpimg)
def backfn(obj):
self.startgame(app)
back.bind(on_press = backfn)
return self.root
示例3: build
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import add_widget [as 别名]
def build(self):
#game = KurveGame()
self.root = FloatLayout()
#android audio. Comment next 2 lines to use on android
self.sound = SoundLoader.load(filename = 'assets/song.mp3')
self.sound.play()
loadscreen = Image(source='assets/intro.png')
x,y = 1280,736
start = Button(text = "PLAY! ",font_size = 30,pos = (x-x*3/8,y/10),size=(x/4,y/8))
help1 = Button(text = "Help",font_size = 20,pos = (x/8,y/10),size=(x/8,y/8))
start.bind(on_press = self.startgame)
help1.bind(on_press = self.loadhelp)
loadscreen.add_widget(start)
loadscreen.add_widget(help1)
self.root.add_widget(loadscreen)
return self.root
示例4: CustomLayout
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import add_widget [as 别名]
class CustomLayout(FloatLayout):
def __init__(self, **kwargs):
# make sure we aren't overriding any important functionality
super(CustomLayout, self).__init__(**kwargs)
self.imag1 = Image(source="fundal.jpg")
self.imag1.opacity = 0.5
self.add_widget(self.imag1)
self.but1 =Button(text = "Butonul 1",bold =True, background_color = (0,0,1,1))
self.but1.pos = (350,300)
self.but1.size_hint = (1,0.05)
self.but1.opacity = 0.5
self.imag1.add_widget(self.but1)
self.but2 =Button(text = "Butonul 2",bold =True, background_color = (0,0,1,1))
self.but2.pos = (350,200)
self.imag1.add_widget(self.but2)
self.but3 =Button(text = "Butonul 3",bold =True, background_color = (0,0,1,1))
self.but3.pos = (350,100)
self.but3.size_hint = (0.3,0.05)
self.imag1.add_widget(self.but3)
示例5: MainScreen
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import add_widget [as 别名]
class MainScreen(AppScreen, BoxLayout):
__background = None # type: Widget
__time = None # type: Label
__date = None # type: Label
def __init__(self, **kwargs):
super(MainScreen, self).__init__(**kwargs)
self.__background = Image()
self.__background.color = [1, 1, 1, 1]
self.add_widget(self.__background)
self.__time = Label()
self.__time.text = "12:00"
self.__time.font_size = 200
self.__time.pos = (337, 225)
self.__time.color = [0, 0, 0, 1]
self.__background.add_widget(self.__time)
self.__date = Label()
self.__date.text = "Sat 13.02.2016"
self.__date.font_size = 50
self.__date.pos = (337, 100)
self.__date.color = [0, 0, 0, 1]
self.__background.add_widget(self.__date)
TimeManager.instance.register_time_listener(self.__timemanager_timechanged)
TimeManager.instance.register_date_listener(self.__timemanager_datechanged)
def _on_resize(self):
pass
def update_time(self, hours: int, minutes: int):
string = ""
if hours < 10:
string += "0"
string += str(hours) + ":"
if minutes < 10:
string += "0"
string += str(minutes)
self.__time.text = string
def update_date(self, weekday: str, day: int, month: int, year: int):
self.__date.text = weekday + " " + str(day) + "." + str(month) + "." + str(year)
def on_set(self):
pass
def on_unset(self):
pass
def __timemanager_timechanged(self, hours: int = None, minutes: int = None, seconds: int = None):
self.update_time(hours, minutes)
def __timemanager_datechanged(self, year: int = None, month: int = None, day: int = None, weekday: int = None):
wd = ""
if weekday == 0:
wd = "Mon"
elif weekday == 1:
wd = "Tue"
elif weekday == 2:
wd = "Wed"
elif weekday == 3:
wd = "Thu"
elif weekday == 4:
wd = "Fri"
elif weekday == 5:
wd = "Sat"
elif weekday == 6:
wd = "Sun"
self.update_date(wd, day, month, year)
示例6: RLMapWidget
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import add_widget [as 别名]
class RLMapWidget(RelativeLayout, Listener):
"""
Game map widget. Mostly is busy displaying character widgets and such.
Assumes that its parent has the following attributes:
self.parent.boombox a dict of SoundLoader instances with correct sounds
"""
# A list of events that should be ignored by the animation system
# 'queue_exhausted' is not included here as self.process_game_event() processes it separately
non_animated = {'log_updated',
'inventory_updated',
'hp_changed',
'ammo_changed'}
def __init__(self, map=None, **kwargs):
super(RLMapWidget, self).__init__(**kwargs)
# Connecting to map, factories and other objects this class should know about
self.tile_factory = TileWidgetFactory()
self.map = map
self.size = [self.map.size[0]*32, self.map.size[1]*32]
# Adding LayerWidgets for every layer of the map
self.layer_widgets = {}
for layer in self.map.layers:
self.layer_widgets.update({layer: LayerWidget(layer=layer, parent=self)})
self.add_widget(self.layer_widgets[layer])
# This is set to True during animation to avoid mistakes
self.animating = False
# Queue of GameEvents to be animated
self.animation_queue = []
# A temporary widget slot for stuff like explosions, spell effects and such
self.overlay_widget = None
# Debugging Dijkstra map view
if DISPLAY_DIJKSTRA_MAP:
self.dijkstra_widget = None
# self.dijkstra_widget = DijkstraWidget(parent=self)
# self.add_widget(self.dijkstra_widget)
self.counter = 0
#########################################################
#
# Stuff related to animation
#
##########################################################
def process_game_event(self, event):
"""
Process a GameEvent passed by queue
:param event: GameEvent
:return:
"""
if event.event_type == 'queue_exhausted':
# Shoot animations only after the entire event batch for the turn has arrived
# Better to avoid multiple methods messing with self.animation_queue simultaneously
self.animate_game_event()
# Ignore non-animatable events
else:
self.animation_queue.append(event)
def animate_game_event(self, widget=None, anim_duration=0.2):
"""
Process a single event from self.animation_queue
Read the event and perform the correct actions on widgets (such as update text of log window,
create and launch animation, maybe make some sound). The event is removed from self.map.game_events.
After the actions required are performed, the method calls itself again, either recursively, or, in
case of animations, via Animation's on_complete argument. The recursion is broken when event queue is
empty.
:return:
"""
if widget and widget.parent and widget.height == 0:
# If the widget was given zero size, this means it should be removed
# This entire affair is kinda inefficient and should be rebuilt later
widget.parent.remove_widget(widget)
if not self.animation_queue == []:
event = self.animation_queue.pop(0)
if event.event_type == 'moved':
final = self.get_screen_pos(event.actor.location, center=True)
if final[0] < event.actor.widget.pos[0] and event.actor.widget.direction == 'right'\
or final[0] > event.actor.widget.pos[0] and event.actor.widget.direction == 'left':
event.actor.widget.flip()
a = Animation(center=final, duration=anim_duration)
a.bind(on_start=lambda x, y: self.remember_anim(),
on_complete=lambda x, y: self.animate_game_event(widget=y))
a.start(event.actor.widget)
elif event.event_type == 'attacked':
current = self.get_screen_pos(event.actor.location, center=True)
target = self.get_screen_pos(event.location, center=True)
if target[0] > current[0] and event.actor.widget.direction == 'left' or\
target[0] < current[0] and event.actor.widget.direction == 'right':
event.actor.widget.flip()
a = Animation(center_x=current[0]+int((target[0]-current[0])/2),
center_y=current[1]+int((target[1]-current[1])/2),
duration=anim_duration/2)
a += Animation(center_x=current[0], center_y=current[1], duration=anim_duration/2)
a.bind(on_start=lambda x, y: self.remember_anim(),
on_complete=lambda x, y: self.animate_game_event(widget=y))
a.start(event.actor.widget)
self.parent.boombox['attacked'].seek(0)
self.parent.boombox['attacked'].play()
elif event.event_type == 'was_destroyed':
if not event.actor.widget:
# If actor is None, that means it was destroyed right after spawning, not getting a
#.........这里部分代码省略.........
示例7: View
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import add_widget [as 别名]
class View(App):
WINDOW_WIDTH = 800
WINDOW_HEIGHT = 600
def __init__(self, controller, **kwargs):
self.controller = controller
super(View, self).__init__(**kwargs)
def build(self):
self.dni = True
self.startPicker = None
self.endPicker = None
self.cosine = False
self.path = None
self.fileName = None
self.progressPopupDescription = None
print "Building Main Window"
layout = BoxLayout(orientation='vertical')
topBarLayout = BoxLayout(orientation='horizontal')
mapWidget = self._generateMap()
topBarLayout.add_widget(mapWidget)
layout.add_widget(topBarLayout)
self.label = Label(text="Use the pin above to select a latitude and longitude.")
self.progressBar= ProgressBar(max=1)
bottomLeftBox = BoxLayout(orientation='vertical')
bottomLeftBox.add_widget(self.label)
# bottomLeftBox.add_widget(self.progressBar)
bottomLeftBox.add_widget(self._generateExportButton())
bottomLeftBox.add_widget(self._generateExportGHIButton())
# bottomLeftBox.add_widget(self._generateHeatmapButton())
# bottomLeftBox.add_widget(self._generateRunSimulationButton())
self.bottomBarLayout = BoxLayout(size_hint=(1,0.5))
self.bottomBarLayout.add_widget(bottomLeftBox)
self.bottomBarLayout.add_widget(self._generateDatetimePicker())
layout.add_widget(self.bottomBarLayout)
return layout
def updateProgressBar(self, progress):
if self.progressBar is not None:
self.progressBar.value = progress
if self.progressPopupDescription is not None:
self.progressPopupDescription.text = "Generating ("+str(round(progress * 1000)/10.0) + " %)"
def _generateDatetimePicker(self):
layout = BoxLayout(orientation='vertical')
startDatetime = self.controller.getSolarStartDatetime()
endDatetime = startDatetime + datetime.timedelta(days=7)
#create new datetime objects because we need timezone-naive versions for the datetimepicker class.
startDatetime = datetime.datetime(year=startDatetime.year, month=startDatetime.month, day=startDatetime.day, hour=startDatetime.hour, minute=startDatetime.minute, tzinfo=None)
endDatetime = datetime.datetime(year=endDatetime.year, month = endDatetime.month, day = endDatetime.day, hour = endDatetime.hour, minute=endDatetime.minute, tzinfo = None)
self.startPicker = FlexiDatetimePicker(density=3, initialDatetime= startDatetime)
self.endPicker = FlexiDatetimePicker(density = 3, initialDatetime = endDatetime)
startLabel = Label(text="Choose Start Date")
endLabel = Label(text="Choose End Date")
layout.add_widget(startLabel)
layout.add_widget(self.startPicker)
layout.add_widget(endLabel)
layout.add_widget(self.endPicker)
return layout
def displayErrorMessage(self,message="default"):
print "Building Popup"
button = Button(text="Close")
label = Label(text=message)
layout= BoxLayout(orientation='vertical')
layout.add_widget(label)
layout.add_widget(button)
popup = Popup(title="Error",content=layout,size_hint=(None, None), size=(400, 400))
button.bind(on_press=lambda widget:popup.dismiss())
popup.open()
print "Popup Opened."
def _on_checkbox_active(self,checkbox, value):
if value:
self.cosine = True
else:
self.cosine = False
def _displayHeatmapGenerationPopup(self, press):
print "Building Heatmap Generation Box"
self.progressPopupDescription = Label(text = "Generating Heatmaps can take a long time. \nAre you sure you want to do this?")
self.heatmapButton = Button(text="Generate")
self.heatmapButton.bind(on_press=self._generateHeatmap)
checkbox = CheckBox()
checkbox.bind(active=self._on_checkbox_active)
cancelButton = Button(text="Cancel")
layout = BoxLayout(orientation='vertical')
#.........这里部分代码省略.........
示例8: Screen
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import add_widget [as 别名]
class Screen(FloatLayout):
def build(self):
self.object1 = BoxLayout()
return self.object1
def __init__(self, **kwargs):
super(Screen, self).__init__(**kwargs)
#Fundal image
with self.canvas.before:
self.fundal_image = Image(source = "E:/PROGRAMMIN/Curs/Pentru examen/fisiere proiect/fundal.jpg")
self.fundal_image.opacity = 0.7
self.add_widget(self.fundal_image)
self.rect = Rectangle(size = self.size, pos = self.pos)
self.bind(size = self._update_rect, pos = self._update_rect)
self.layout = FloatLayout()
self.layout.size_hint = (None, None)
self.layout.size = (600, 500)
self.layout.padding = 20
self.fundal_image.add_widget(self.layout)
self.sound = SoundLoader.load("E:/PROGRAMMIN/Curs/Pentru examen/fisiere proiect/JO_-_09_-_Fortitude.ogg")
self.sound.play()
self.sound.loop = True
self.sound.volume = 0.5
self.Menu(None)
def Menu(self, buton):
self.layout.clear_widgets()
self.button1 = Button(text = 'Carousel', bold = True, background_color =(0, 0, 1, 1))
self.button1.pos = (290, 380)
self.button1.size_hint = (0.3, 0.1)
self.layout.add_widget(self.button1)
self.button2 = Button(text = 'Optiuni', bold = True, background_color =(0, 0, 1, 1))
self.button2.pos = (290, 280)
self.button2.size_hint = (0.3, 0.1)
self.layout.add_widget(self.button2)
self.button3 = Button(text = 'About', bold = True, background_color =(0, 0, 1, 1))
self.button3.pos = (290, 180)
self.button3.size_hint = (0.3, 0.1)
self.layout.add_widget(self.button3)
self.button4 = Button(text = 'Iesi', bold = True, background_color =(0, 0, 1, 1))
self.button4.pos = (290, 80)
self.button4.size_hint = (0.3, 0.1)
self.layout.add_widget(self.button4)
self.button1.bind(on_press = self.Carousel)
self.button2.bind(on_press = self.Options)
self.button3.bind(on_press = self.About)
self.button4.bind(on_press = self.Exit)
def Carousel(self, buton):
self.layout.clear_widgets()
self.carousel = Carousel(direction = 'right')
self.carousel.anim_move_duration = 1
self.carousel.loop = True
self.carousel.size_hint = (0.7, 0.7)
self.carousel.pos = (200, 120)
self.layout.add_widget(self.carousel)
self.image1 = Image(source = 'E:/PROGRAMMIN/Curs/Pentru examen/fisiere proiect/nature1.jpg')
self.carousel.add_widget(self.image1)
self.image2 = Image(source= 'E:/PROGRAMMIN/Curs/Pentru examen/fisiere proiect/nature2.jpg')
self.carousel.add_widget(self.image2)
self.image3 = Image(source = 'E:/PROGRAMMIN/Curs/Pentru examen/fisiere proiect/nature3.jpg')
self.carousel.add_widget(self.image3)
self.image4 = Image(source = 'E:/PROGRAMMIN/Curs/Pentru examen/fisiere proiect/nature4.jpg')
self.carousel.add_widget(self.image4)
self.label = Label(text = 'This is the end of the list!', font_size = 30)
self.carousel.add_widget(self.label)
self.backbutton = Button(text = 'Back', bold = True, background_color = (0, 0, 1, 1))
self.backbutton.pos = (200, 100)
self.backbutton.size_hint = (0.7, 0.1)
self.layout.add_widget(self.backbutton)
self.backbutton.bind(on_press = self.Menu)
def Options(self, buton):
self.layout.clear_widgets()
self.switch = Switch(text = 'Music')
self.switch.active = True
self.switch.size_hint = (0.3, 0.2)
self.switch.pos = (300, 360)
self.layout.add_widget(self.switch)
self.show_volume = Label(text = 'Volume = 50')
#.........这里部分代码省略.........
示例9: SettingPos
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import add_widget [as 别名]
class SettingPos(SettingString):
'''Implementation of a string setting on top of a :class:`SettingItem`.
It is visualized with a :class:`~kivy.uix.label.Label` widget that, when
clicked, will open a :class:`~kivy.uix.popup.Popup` with a
:class:`~kivy.uix.textinput.Textinput` so the user can enter a custom
value.
'''
popup = ObjectProperty(None, allownone=True)
'''(internal) Used to store the current popup when it's shown.
:attr:`popup` is an :class:`~kivy.properties.ObjectProperty` and defaults
to None.
'''
# position = ObjectProperty(None)
'''(internal) Used to store the current textinput from the popup and
to listen for changes.
:attr:`textinput` is an :class:`~kivy.properties.ObjectProperty` and
defaults to None.
'''
pic = StringProperty()
position = StringProperty('50*50')
def __init__(self, **kwargs):
super(SettingPos, self).__init__(**kwargs)
self.img = Image(source=self.pic)
def on_panel(self, instance, value):
if value is None:
return
self.bind(on_release=self._create_popup)
def _dismiss(self, *largs):
if self.popup:
self.popup.dismiss()
self.popup = None
def _register(self, instance, touch):
if self.img.collide_point(*touch.pos):
# self.position = '*'.join([str(p) for p in touch.pos])
# print(touch)
# print(self.img.pos)
# print(self.img.size)
# print(Window.size)
x, y = self.img.to_widget(touch.pos[0], touch.pos[1], True)
x = x - self.img.pos[0] - 20.0
y = y + 68.0
# print('%s * %s' % (x, y))
self.position = str(x) + '*' + str(y)
def _validate(self, instance):
value = self.position
self.value = value
# print(self.value)
self._dismiss()
def _create_popup(self, instance):
# create popup layout
content = BoxLayout(orientation='vertical', spacing='5dp')
# popup_width = min(0.95 * Window.width, dp(500))
self.popup = popup = Popup(
title=self.title, content=content)
pos = [float(c) for c in self.value.split('*')]
scat = ScatterCross(size=(20, 20), size_hint=(None, None), pos=pos)
scat.bind(on_touch_up=self._register)
self.img.add_widget(scat)
content.add_widget(self.img)
content.add_widget(SettingSpacer())
# 2 buttons are created for accept or cancel the current value
btnlayout = BoxLayout(size_hint_y=None, height='50dp', spacing='5dp')
btn = Button(text='Ok')
btn.bind(on_release=self._validate)
btnlayout.add_widget(btn)
btn = Button(text='Cancel')
btn.bind(on_release=self._dismiss)
btnlayout.add_widget(btn)
content.add_widget(btnlayout)
# all done, open the popup !
popup.open()