我给一个按钮分配了一个on_funtion,.Which应该运行一个python文件并开始捕获网络摄像头。只应在单击按钮时启动该按钮。但是,每当我运行流光服务器时,这个函数就会运行并开始捕获,而不需要单击事件。同样的事情发生在我做的表单上,它导致了写到google的空数据。
以下是代码:
import subprocess
import sys
import streamlit as st
from activity_check import high_count
act_lev = ""
def start_capture():
subprocess.run([f"{sys.executable}", "activity_check.py"])
def run_cap():
st.button("Start Capturing",on_click=start_capture)
run_cap()
st.write(high_count)该函数只应在我单击时启动,但它将自动执行。
我以为送礼物会有帮助

发布于 2022-08-09 10:07:23
试着让你的按钮有条件。
import subprocess
import sys
import streamlit as st
from activity_check import high_count
act_lev = ""
def start_capture():
subprocess.run([f"{sys.executable}", "activity_check.py"])
def run_cap():
cap_button = st.button("Start Capturing") # Give button a variable name
if cap_button: # Make button a condition.
start_capture()
st.text("Captured Successfully")
run_cap()
st.write(high_count) https://stackoverflow.com/questions/73289728
复制相似问题