使用askopenfilename()函数为另一个脚本设置新路径

时间:2019-03-07 21:16:30

标签: python tkinter

我目前正在通过tkinter与gui合作进行分配。每当我运行gui脚本时,我都想在objectdetector.py中为变量设置新路径。但是我收到一个错误,其中tkinter窗口一直弹出而不是执行我想要的操作。这是我的代码:

try2.py

from tkinter import Tk,messagebox
from tkinter.filedialog import askopenfilename
from tkinter import *
import os

window=Tk()
window.title("Wildlife Monitoring System")
window.geometry('400x400')


var = IntVar()
var.set(0)

R1 = Radiobutton(window, text="Webcam", variable=var, value=1)
R1.place(relx=.25, rely=.55, anchor="c")

R2 = Radiobutton(window, text="Input Video", variable=var, value=2)
R2.place(relx=.75, rely=.55, anchor="c")

def open():
    selection=var.get()
    if selection == 2:
        file=askopenfilename(title="Select an input video")
        window.destroy()
        os.system('objectdetector.py')     
    elif selection == 0:
        messagebox.showinfo("Error", "Please select an option.")
    elif selection == 1:
        window.destroy()
        os.system('try.py')
    return           

btn = Button(window, text="Start",command=lambda: open(), height= 2, width=10)

btn.place(relx=.5, rely=.35, anchor="c")

window.mainloop()

object.detector.py 

对于objectdetector.py(仅作为示例)

from try2 import file

path = 'file'

print(path)

0 个答案:

没有答案