猫史档案馆


【求助帖】有没有人知道如何实现此效果

用户:旺旺狗旺旺狗查看:10 回复:3 评论:10 创建时间:2021-08-02T20:31:28


我想在Python程序中实现这样一个效果:在显示easygui的窗口的同时检测某一条件是否成立,若成立则执行某些相对应的脚本,但窗口保持。有没有人知道怎么弄?给个框架就行,谢谢emotion_可怜


回复

上一页1 页 / 共 1下一页
伴雪纷飞伴雪纷飞

em....emotion_最右

不大了解啥意识

可以描述再清楚一点吗?

不过按照上述表达大概可以给你提供一个思路

用threading库(自带

创造线程一直监听

点赞0


评论


wwwloadwwwload

你可以用easygui.buttonbox或者easygui.choicebox

点赞0


评论


lsk666666lsk666666

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


评论