询问对话框保存在错误的地图中

时间:2019-04-23 12:15:40

标签: python-3.x tkinter

当要求选择保存文件位置时,我将选择一个名为“ timelapse”的地图。 但图片会在延时拍摄之前保存在地图中。如 / home / pi而不是/ home / pi / timelapse

似乎我不小心在代码中放置了默认保存位置?因为它不会更改位置,但我从未对其进行编码,因此在/ home / pi

中应该特别安全

我尝试在文本中手动添加“ /”,希望它会打开延时摄影图,但出现错误,权限被拒绝。 创建其他子图无效,它仍保存在/ home / pi

class Capture:
    def __init__(self, waittime=30):
        self.capture_stop = False
        self.capture_waittime = waittime
        self.thread = None
        self.capture_running = False
        self.folder = ''


    def capture_worker(self):
        self.capture_running = True

        try:
            with picamera.PiCamera() as camera:
                camera.resolution = (1024, 768)

                for filename in camera.capture_continuous(self.folder+'-{timestamp:%H-%M-%S-%f}.jpg'):
                  i = 0
                  while i < self.capture_waittime:
                      time.sleep(0.1)
                      i += 0.1
                      if self.capture_stop:
                        return
        finally:
            self.capture_running = False
            self.capture_stop = False

    def start(self):
        if not self.capture_running:
            self.thread = threading.Thread(target=self.capture_worker)
            self.capture_stop = False
            self.thread.start()

    def stop(self):
        if self.capture_running:
            self.capture_stop = True

    def isRunning(self):
        return self.capture_running

    def setWaitTime(self, waittime):
        self.capture_waittime = waittime

    def setFolder(self, folder):
        capture.setFolder(folder)
        self.folder = folder




capture = Capture()


def startButton():
    interval = float(var_2.get())
    capture.setWaitTime(interval)
    capture.start()


def stopButton():
    capture.stop()


def chooseDir():
        root.folder = filedialog.askdirectory(
        parent=root, initialdir="/home/pi/", title='Please choose a save location')

我希望这些图片将保存在我专门选择的地图中。我也希望对我的Ask对话代码有所批评,以便改进它。

0 个答案:

没有答案