这是我的python代码:
class Filechooser(Screen):
def select(self, *args):
try: self.label.text = args[1][0]
except: pass
def load(self,path):
with open(path) as stream:
global file_directory
file_directory=stream.read()
self.dismiss_popup()
当我选择一个文件夹并单击“加载”时,就会出现此错误:
File "main.py", line 19, in load
with open(path) as stream:
PermissionError: [Errno 13] Permission denied: 'C:\\movies'
它显示权限错误,我该怎么办
答案 0 :(得分:0)
我无法做你想做的事,但我发现你可以使用 tkinter 来完成这项任务。顺便说一句,我正在使用 StringProperty 来存储路径,我不知道这是否是正确的方法,我是 Kivy 的新手。
KV
<BrowseApp>:
cols: 2
Button:
text: 'Browse...'
size_hint_x: 0.3
on_release: root.get_path()
Label:
id: pathLabel
text: root.pathVar
PY
# Import modules
import tkinter as tk
from tkinter import filedialog
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.properties import *
from kivy.core.window import Window
Window.size = (600, 50)
class BrowseApp(GridLayout):
# variable to store path dir
pathVar = StringProperty("< Select a folder >")
# Function to select dir
def get_path(self):
root = tk.Tk()
root.withdraw()
pathVar = filedialog.askdirectory()
self.ids.pathLabel.text = pathVar # Change text of label
# ---- App Class
class loader(App):
def build(self):
return BrowseApp()
if __name__ == "__main__":
loader().run()