使用kivy上传文件

2024-09-25 02:38:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个注册屏幕,允许用户上传简历和其他文件。我尝试使用filechooser执行此操作,但它不起作用。你对如何做有什么建议吗

class SignupWindow(Screen):

    first_name: ObjectProperty(None)
    middle_name: ObjectProperty(None)
    last_name: ObjectProperty(None)
    email2 = ObjectProperty(None)
    password2: ObjectProperty(None)
    profession: ObjectProperty(None)

       
    def signupbtn(self):
        user = auth.create_user_with_email_and_password(self.email2.text, self.password2.text)
        auth.send_email_verification(user['idToken'])
        user_info = {
            u'Last name' : self.last_name.text,
            u'Middle name' : self.middle_name.text,
            u'First name': self.first_name.text,
            u'Email' : self.email2.text,
            u'Profession' : self.profession.text,
            u'birth' : self.birth.text
        }
        db.collection(u'users').document(self.email2.text).set(user_info)
        sm.current = 'login'

    def Resume_selection(self):
        image_path = self.fc.selection[0]
        image_name = file_path.split('/')[-1]
<SignupWindow>:
    first_name: first_name
    middle_name: middle_name
    last_name: last_name
    email2: email2
    password2: password2
    profession: profession
    birth: birth
    phone: phone
    resume: resume


    ScrollView:

        GridLayout:
            orientation: "vertical"
            size_hint_y: None
            height: self.minimum_height
            row_default_height: 30
            cols:2
            spacing: 15, 15
            padding: 100, 100

            Label:
                text : "First Name: "

            TextInput:
                id : first_name
                hint_text: "First name"
                multiline : False

            Label:
                text : "Middle Name: "

            TextInput:
                id : middle_name
                hint_text: "Middle name"
                multiline : False

            Label:
                text : "Last Name: "

            TextInput:
                id : last_name
                hint_text: "Last name"
                multiline : False

            Label:
                text : "Date of Birth: "

            TextInput:
                id : birth
                hint_text: "mm/dd/yyyy"
                multiline : False

            Label:
                text : "Email: "

            TextInput:
                id : email2
                hint_text: "email@domain.com"
                multiline : False

            Label:
                text : "Password: "

            TextInput:
                id : password2
                hint_text: "Choose a password"
                multiline : False
                password: True


            Label:
                text : "Password: "

            TextInput:
                hint_text: "Type your password again"
                multiline : False
                password: True


            Label:
                text : "Phone number: "

            TextInput:
                id : phone
                hint_text: "xxx-xxx-xxxx "
                multiline : False



            Label:
                text : "Profession: "

            TextInput:
                id : profession
                hint_text: "Profession"
                multiline : False

            Label:
                text : "Resume: "

            #TextInput:
                id : resume
                hint_text: "Please attach your Resume"
                multiline : False

            #FileChooserIconView:
                id: resume
                text: "Upload Resume"

            FileChooserIconView:
                id:filechooser
                title: 'Upload a resume'
                size: self.size
                pos : self.pos
                
                on_selection : root.Resume_selection(filechooser.selection)

            Button:
                text : "Submit"
                on_press :
                    root.signupbtn()
                    root.manager.transition.direction = "right"

            Button:
                text : "Login"
                on_release:
                    root.manager.current = 'login'
                    root.manager.transition.direction = "up"

错误如下:

[错误]无法访问<\hiberfil.sys>; 回溯(最近一次呼叫最后一次): 文件“C:\Users\remio\PycharmProjects\pythonProject1\venv\lib\site packages\kivy\uix\filechooser.py”第178行隐藏在 返回GetFileAttributesExW(fn)[0]&;文件\属性\隐藏 pywintypes.error:(32,'GetFileAttributesEx','该进程无法访问该文件,因为它正被另一个进程使用。')) [错误]无法访问<\pagefile.sys>; 回溯(最近一次呼叫最后一次): 文件“C:\Users\remio\PycharmProjects\pythonProject1\venv\lib\site packages\kivy\uix\filechooser.py”第178行隐藏在 返回GetFileAttributesExW(fn)[0]&;文件\属性\隐藏 pywintypes.error:(32,'GetFileAttributesEx','该进程无法访问该文件,因为它正被另一个进程使用。')) [错误]无法访问<\交换文件系统>; 回溯(最近一次呼叫最后一次): 文件“C:\Users\remio\PycharmProjects\pythonProject1\venv\lib\site packages\kivy\uix\filechooser.py”第178行隐藏在 返回GetFileAttributesExW(fn)[0]&;文件\属性\隐藏 pywintypes.error:(32,'GetFileAttributesEx','该进程无法访问该文件,因为它正被另一个进程使用。'))

signup screen picture

谢谢


Tags: 文件textnameselfnoneidfalse进程