В настоящее время я работаю с GUI для моего назначения с помощью tkinter. Я хотел бы установить новый путь для моей переменной в 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)