秒表python Tkinter代码未打开烧瓶中的弹出窗口。如果只运行python脚本,则运行良好。控制台上没有抛出错误
如果只运行StopWatch.py脚本,它将完美地提供所需的输出 但是,当url:打开时,python脚本Stopwatch.py不会根据需要显示任何计时器 我几乎花了一整天的时间,但无法通过flask应用程序获得所需的输出 代码如下: app.py秒表python Tkinter代码未打开烧瓶中的弹出窗口。如果只运行python脚本,则运行良好。控制台上没有抛出错误,python,python-3.x,flask,tkinter,stopwatch,Python,Python 3.x,Flask,Tkinter,Stopwatch,如果只运行StopWatch.py脚本,它将完美地提供所需的输出 但是,当url:打开时,python脚本Stopwatch.py不会根据需要显示任何计时器 我几乎花了一整天的时间,但无法通过flask应用程序获得所需的输出 代码如下: app.py from flask import Flask, render_template, request import subprocess activity = "" attuid = "" duration = 0 app = Flask(__n
from flask import Flask, render_template, request
import subprocess
activity = ""
attuid = ""
duration = 0
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST' :
activity = request.form.get('activity')
attuid = request.form.get('attuid')
cmd = 'StopWatch.py'
duration = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
print(activity, attuid, duration)
return render_template('index.html')
import tkinter as Tkinter
import time
counter = -1
initial=0
duration=0
running = False
def counter_label(label):
def count():
if running:
global counter
# To manage the intial delay.
if counter==-1:
display="Starting..."
else:
display=str(counter)
label['text']=display # Or label.config(text=display)
# label.after(arg1, arg2) delays by
# first argument given in milliseconds
# and then calls the function given as second argument.
# Generally like here we need to call the
# function in which it is present repeatedly.
# Delays by 1000ms=1 seconds and call count again.
label.after(1000, count)
counter += 1
# Triggering the start of the counter.
count()
# start function of the stopwatch
def Start(label):
global running
global initial
running=True
counter_label(label)
start['state']='disabled'
stop['state']='normal'
initial = time.time()
return initial
# Stop function of the stopwatch
def Stop():
global running
global final
global duration
start['state']='disabled'
stop['state']='disabled'
running = False
final = time.time()
duration = round(final - initial,2)
label['text'] = (" Total duration of activity is :", duration, "seconds" )
return duration
root = Tkinter.Tk()
root.title("Stopwatch")
# Fixing the window size.
root.minsize(width=250, height=70)
label = Tkinter.Label(root, text="Welcome!", fg="black", font="Verdana 30 bold")
label.pack()
start = Tkinter.Button(root, text='Start',
width=15, command=lambda:Start(label))
stop = Tkinter.Button(root, text='Stop',
width=15, state='disabled', command=Stop)
start.pack()
stop.pack()
index.html
<html>
<head>
<title>Leads Activity Tracker Automation</title>
</head>
<body>
<form method="POST" action="/">
<h3>Select an activity</h3>
<input type="radio" value="TROUBLESHOOTING_CPDO_ISSUES" name="activity">TROUBLESHOOTING_CPDO_ISSUES<br>
<input type="radio" value="MAJOR_EVENT_HEALTH_CHECKS" name="activity">MAJOR_EVENT_HEALTH_CHECKS<br>
<input type="radio" value="TRAINING_PEERS" name="activity">TRAINING_PEERS<br>
<input type="radio" value="UPDATE_JOB_AID_AND_PROCESSES" name="activity">UPDATE_JOB_AID_AND_PROCESSES<br><br>
<input type="text" value="attuid" name="attuid">
<input type="submit">
</form>
您是否检查了
popen
的返回值以查看进程是否成功运行?您不应该在web应用程序中运行GUI应用程序,因为客户端不会看到它。您是否检查了popen
的返回值以查看进程是否成功运行?您不应该在web应用程序中运行GUI应用程序,因为它不会成功运行被客户看到。