Can some please help me start a code that displays more than one image horizontally
or vertically. These images should be to display other pages when clicked.
我曾尝试编写不同类型的代码,但他们从未按预期执行程序。
例如:
<MainPage>:
Image:
size: (1, None)
#pos_hint:
source: 'desktop/advisory.png'
on_press: open.adivsorypage()
如果有人能给我一个视觉范例或样本供我学习,我会很喜欢。谢谢!
**编辑:
import kivy
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.image import Image
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App
class InterfaceManager(BoxLayout):
def __init__(self, **kwargs):
super(InterfaceManager, self).__init__(**kwargs)
self.first = Button(text="First")
self.first.bind(on_press=self.show_second)
self.second = Image(source="parentaladvisory.jpg")
self.second.bind(on_press=self.show_final)
self.final = Label(text="Hello World")
self.add_widget(self.first)
#I wanted to make the "final" display two of more images.
def show_second(self, button):
self.clear_widgets()
self.add_widget(self.second)
def show_final(self, button):
self.clear_widgets()
self.add_widget(self.final)
class MyApp(App):
def build(self):
return InterfaceManager(orientation='vertical')
if __name__ == '__main__':
MyApp().run()
代码2:
from kivy.uix.popup import Popup
from kivy.uix.button import Button
from kivy.app import App
from kivy.uix.image import Image
from kivy.lang import Builder
Builder.load_string('''
<MainPage>:
size_hint: .5, .5
auto_dismiss: False
title: 'Hello world'
HelpMe_Image:
source: 'helpme.png'
on_press: root.dismiss()
Games_Image:
source: 'games.png'
on_press: root.dismiss()
''')
class MainPage(App):
pass
class TestApp(App):
def build(self):
b = Button(source='desktop/intrologo2.png', on_press=self.show_mainpage)
return b
def show_mainpage(self, b):
p = MainPage()
p.open()
TestApp().run()