I want run python file which opens camera preview by Tkinter button that placed on the main window.But it runs automatically camera window without opening the main window when executing the code.
from tkinter import *
import tkinter as tk
import os
window = tk.Tk()
window.title("Camera")
window.geometry("640x480")
lbl=Label(window,text="Start", font=("Arial Bold",10))
lbl.grid(column=0,row=0)
btn = Button(window, text="Start",command=os.system('capture.py'))
btn.grid(column=1, row=0)
window.mainloop()
It should be command=lambda: os.system('capture.py')
:
btn = Button(window, text="Start",command=lambda: os.system('capture.py'))
btn.grid(column=1, row=0)
If you use ()
near a function name, it will call the function immediately. Which is not what you want, you want it to be called upon press, so just pass the function name(with lambda
if it has arguments) and tkinter
will handle the rest.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments