文件系统模拟程序python_将图像从文件系统下载到kivy应用程序

fromkivymd.appimportMDAppfromkivy.core.windowimportWindowfromkivy.langimportBuilderfromkivy.factoryimportFactoryfromkivy.uix.modalviewimportModalViewfromplyerimportstoragepathfromkivymd.uix.filemanagerimportMDFileManagerfromkivymd.themingimportThemeManagerfromkivymd.toastimporttoastBuilder.load_string('''

orientation: 'vertical'

spacing: dp(5)

MDToolbar:

id: toolbar

title: app.title

left_action_items: [['menu', lambda x: None]]

elevation: 10

md_bg_color: app.theme_cls.primary_color

FloatLayout:

MDRoundFlatIconButton:

text: "Open manager"

icon: "folder"

pos_hint: {'center_x': .5, 'center_y': .6}

on_release: app.file_manager_open()

''')classExample(MDApp):title="File Manage"def__init__(self,**kwargs):super().__init__(**kwargs)Window.bind(on_keyboard=self.events)self.manager_open=Falseself.manager=Nonedefbuild(self):returnFactory.ExampleFileManager()deffile_manager_open(self):ifnotself.manager:self.manager=ModalView(size_hint=(1,1),auto_dismiss=False)self.file_manager=MDFileManager(exit_manager=self.exit_manager,select_path=self.select_path)self.manager.add_widget(self.file_manager)self.file_manager.show(storagepath.get_home_dir())# output manager to the screenself.manager_open=Trueself.manager.open()defselect_path(self,path):'''It will be called when you click on the file name

or the catalog selection button.

:type path: str;

:param path: path to the selected directory or file;

'''self.exit_manager()toast(path)defexit_manager(self,*args):'''Called when the user reaches the root of the directory tree.'''self.manager.dismiss()self.manager_open=Falsedefevents(self,instance,keyboard,keycode,text,modifiers):'''Called when buttons are pressed on the mobile device..'''ifkeyboardin(1001,27):ifself.manager_open:self.file_manager.back()returnTrueExample().run()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值