我试图加载一个文件选择器弹出窗口时,图像按钮被按下,并选择一个图像,以取代我的kivy/python文件中的图像,但我招致了一个错误的代码,这里是我的mre。任何帮助都将不胜感激
主文件.py
import kivy
from kivy.properties import ObjectProperty
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.popup import Popup
from kivy.uix.button import ButtonBehavior
from kivy.uix.image import Image
from kivy.lang import Builder
from kivy.app import App
class ImageButton(ButtonBehavior, Image):
pass
class LoadDialog(FloatLayout):
load = ObjectProperty(None)
save = ObjectProperty(None)
class ProfileWindow(Screen):
load = ObjectProperty(None)
cancel = ObjectProperty(None)
def __init__(self, **kwargs):
super(ProfileWindow, self).__init__(**kwargs)
self.profileimage = ImageButton(source= "icons/profilepic.png", pos_hint={"center_x": 0.5, "center_y": 0.65})
self.profileimage.bind(on_release= self.imagechange)
self.add_widget(self.profileimage)
def imagechange(self, instance):
content = LoadDialog(load=self.load_list, cancel=self.dismiss_popup)
self._popup = Popup(title="Load a file list", content=content, size_hint=(1, 1))
self._popup.open()
def load_list(self, path, filename):
pass
def dismiss_popup(self):
self._popup.dismiss()
kv = Builder.load_file("kivy.kv")
class WindowManager(ScreenManager):
pass
sm = WindowManager()
sm.current = "page"
class MyApp(App):
def build(self):
return sm
if __name__ == "__main__":
MyApp().run()
千伏
<WindowManager>:
id: window_manager
ProfileWindow:
id: page
name: "page"
<ProfileWindow>:
full_name: fullname
jobs: jobs
canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
<LoadDialog>:
BoxLayout:
size: root.size
pos: root.pos
orientation: "vertical"
FileChooserListView:
id: filechooser
path: './'
BoxLayout:
size_hint_y: None
height: 30
Button:
text: "Cancel"
on_release: root.cancel()
Button:
text: "Load"
on_release: root.load(filechooser.path, filechooser.selection)
如能提供任何帮助,我们将不胜感激。我是kivy和python的新手
在
LoadDialog
类中缺少cancel
属性。另外,在
ProfileWindow
类中不需要load
和cancel
属性这是您的
.py
文件:相关问题 更多 >
编程相关推荐