首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Kivy中取消回波器时列出超出范围误差的索引

在Kivy中取消回波器时列出超出范围误差的索引
EN

Stack Overflow用户
提问于 2022-01-22 13:36:28
回答 1查看 162关注 0票数 0

我试图让这个视频上传应用程序到我的防火墙存储,但我被困在这个问题上。当按下上传按钮时,文件回波器将被打开,如果我选择一个文件,它将被上传到firebase。但是,如果取消并关闭文件回波器,则会产生一个错误:

文件"C:\Users\Dheeraj\AppData\Roaming\Python\Python38\site-packages\plyer\platforms\win\filechooser.py",行108,在运行self._handle_selection(self.selection)文件“C:\

\Dheeraj\Desktop\kivy codes\Dheeraj.py",第949行,在选定的Directory=selection IndexError: list索引超出范围的信息中,应用程序仍在进行中.

我不知道这个文件选择器是否在android上工作。如果没有,也请帮我处理这段代码。

版本

  • OS: win 7 pro
  • Python: 3.7
  • Kivy:最新
  • KivyMD:最新(每周更新)

F 211

代码

代码语言:javascript
复制
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.core.window import Window
from kivymd.uix.dialog import MDDialog
import json
from plyer import filechooser
from kivymd.uix.button import MDFlatButton
import requests
import pyrebase
from kivmob import KivMob, TestIds, RewardedListenerInterface
from kivy.properties import NumericProperty, StringProperty,BooleanProperty
from kivymd.uix.label import MDLabel
from kivy.uix.relativelayout import RelativeLayout
import re
from kivy.garden.notification import Notification
from kivymd.uix.behaviors import FakeRectangularElevationBehavior
from kivy.uix.behaviors import ButtonBehavior
from kivymd.uix.floatlayout import MDFloatLayout
import plyer

help_str='''
ScreenManager:
    MainScreen:
<MainScreen>:
    name: 'mainscreen'

    MDFloatLayout:
        id:floate

        Video:
            id:vid

        MDRaisedButton:
            id:upload
            text:'Upload'
            pos_hint:{'center_x':.5, 'center_y':.05}
            on_release:
                app.file_chooser()
                upload.disabled=True


'''
class MainScreen(Screen):
    pass
sm = ScreenManager()
sm.add_widget(MainScreen(name = 'mainscreen'))

class LoginApp(MDApp):
    def build(self):
        self.strng = Builder.load_string(help_str)
        self.url  = "**confidential**.json"
        return self.strng

    def file_chooser(self):
        filechooser.open_file(on_selection=self.selected)        
    def selected(self,selection):
        configure={
            'apiKey': "**confidential**",
            'authDomain': "**confidential**",
            'databaseURL': "**confidential**",
            'projectId': "**confidential**",
            'storageBucket': "**confidential**",
            'messagingSenderId': "**confidential**",
            'appId': "**confidential**",
            'measurementId': "**confidential**",
            'serviceAccount':"**confidential**",
            'databaseURL':'**confidential**' 

                      }
        firebase=pyrebase.initialize_app(configure)
        storage=firebase.storage()            
        Directory=selection[0]
        Name=re.findall('[ \w-]+\..*',Directory)
        storage.child(str(f"{Name}")).put(str(f"{Name[0]}"))

        if selection==true:
            self.root.ids.vid.source=firebase

if __name__=="__main__":
    LoginApp().run()
EN

回答 1

Stack Overflow用户

发布于 2022-02-03 17:00:28

我想我已经搞清楚了,我所要做的就是在它自己的if selection==True语句下缩进所选函数的代码。感谢所有想帮忙的人。

新代码

代码语言:javascript
复制
def selected(self,selection):
    
    if selection==true:
        self.root.ids.vid.source=firebase
        configure={
        'apiKey': "**confidential**",
        'authDomain': "**confidential**",
        'databaseURL': "**confidential**",
        'projectId': "**confidential**",
        'storageBucket': "**confidential**",
        'messagingSenderId': "**confidential**",
        'appId': "**confidential**",
        'measurementId': "**confidential**",
        'serviceAccount':"**confidential**",
        'databaseURL':'**confidential**' 

                  }
    firebase=pyrebase.initialize_app(configure)
    storage=firebase.storage()            
    Directory=selection[0]
    Name=re.findall('[ \w-]+\..*',Directory)
    storage.child(str(f"{Name}")).put(str(f"{Name[0]}"))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70813360

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档