【发布时间】:2018-11-20 09:03:30
【问题描述】:
我做了两台 opc-ua 服务器,一台从文本文件读取标签值,另一台从 SQL 读取值。现在我在 tkinter 中做了一个“服务器菜单”,可以启动服务器等等。 问题是我不能关闭其中一个并让另一个运行, 我想要这样的东西:
import subprocess
def start_txt():
txt = subprocess.Popen("python TAG_TXT.py &", shell=True)
return txt
def stop_txt():
subprocess.Popen('taskkill /F /PID {0}'.format(start_txt(txt)),
shell=True)
def start_SQL():
SQL = subprocess.Popen("python TAG_SQL.py &", shell=True)
return SQL
def stop_SQL():
subprocess.Popen('taskkill /F /PID {0}'.format(start_SQL(txt)),
shell=True)
如果我用这个:
os.system("taskkill /f /im python.exe")
我杀死了两个服务器
错误信息:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-
32\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "C:\PY_OPCUA\servermeny_GUI.py", line 237, in kill_txt
subprocess.Popen('taskkill /F /PID {0}'.format(textfile_server(txt)),
shell=True)
NameError: name 'txt' is not defined
我之前只使用过一次 tkinter,所以它可能很容易修复
【问题讨论】:
标签: python-3.x tkinter