用户:
旺旺狗查看:10 回复:3 评论:10 创建时间:2021-08-02T20:31:28
我想在Python程序中实现这样一个效果:在显示easygui的窗口的同时检测某一条件是否成立,若成立则执行某些相对应的脚本,但窗口保持。有没有人知道怎么弄?给个框架就行,谢谢![]()
from threading import Thread
class SecondThread(Thread):
def __init__(self, condition, onTrue, onFalse):
self.condition = condition
self.onTrue = onTrue
self.onFalse = onFalse
#Invoke the construction method of the father class
Thread.__init__(self)
def run(self):
if condition():
self.onTrue()
else:
self.onFalse()
import random
def main():
def condition():
return (random.randint(1,10) % 2) == 0
def onTrue():
print("True")
def onFalse():
print("False")
# 首先启动线程
secondThread(condition, onTrue, onFalse).start()
# 然后开始用easygui搞事
有错,有问题留言
点赞0
评论