小部件中的可点击图像。基维。python
我尝试过编写不同类型的代码,但它们从未按预期执行它们的程序 例: 代码2:小部件中的可点击图像。基维。python,python,image,widget,kivy,Python,Image,Widget,Kivy,我尝试过编写不同类型的代码,但它们从未按预期执行它们的程序 例: 代码2: 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
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()
从kivy.uix.popup导入弹出窗口
从kivy.uix.button导入按钮
从kivy.app导入应用程序
从kivy.uix.image导入图像
从kivy.lang导入生成器
Builder.load_字符串(“”)
:
大小提示:.5,.5
自动解除:错误
标题:“你好,世界”
HelpMe_图像:
来源:“helpme.png”
按:root.discouse()
游戏图片:
资料来源:“games.png”
按:root.discouse()
''')
类主页(应用程序):
通过
类TestApp(应用程序):
def生成(自):
b=按钮(source='desktop/intrologo2.png',在[u press=self.show]主页上)
返回b
def show_主页(自我,b):
p=主页()
p、 开()
TestApp().run()
如何发布一个完整的最简单的工作示例,说明您正在尝试的内容,或者您能够达到的目的?您的代码片段实际上没有任何作用,因此答案的依据也不多。@Sarment下面是一个示例。老实说,我有更多的8种不同的代码。如果我能发布所有内容,我会。在代码2中,MainPage
扩展了App
,而您可能想扩展弹出窗口
。在这两种情况下,您都将绑定到一个on_press
事件,而Image
没有该事件。尝试使用按钮行为
制作可点击的图像
,如中所示。
<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()
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()