import time
class A():
aa = ""
class tt(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while True:
a.aa = raw_input('enter:')
if a.aa=='Q':
break
def main():
my_t = tt()
my_t.start()
while True:
if a.aa=="A":
continue
elif a.aa=="Q":
break
else:
print('hello',a.aa)
time.sleep(1)
a = A()
main()
使用python自带的gui就可以实现,python自带tk,使用tk的mainloop就会让python程序一直运行,只要让gui窗口一直不显示就是一直在后动员运行了。代码示意如下:fromtkinterimport*root=tk()root.withdraw()#隐藏窗口root.mainloop()#消息循环把代码以pyw扩展名保存,执行一下,就会让程序一直在后台执行,可以通过任务管理器结束,如下: