代码之家  ›  专栏  ›  技术社区  ›  Moshe S.

如何执行延迟的GUI更改,同时能够看到之前和之后的更改?

  •  -1
  • Moshe S.  · 技术社区  · 6 年前

    我的问题是,在返回默认GUI之前用于延迟GUI的“after”函数没有显示before和after。我只看到在字段和按钮已经返回到默认值之后,按钮凹陷然后升高。

    我做错什么了?

    if condition1 == condition2:
         orig_color = self.button2.cget("background")
         self.button2.config(bg='springgreen2')
         self.return2default(orig_color)
         self.after(3000) # 3 seconds delay to realize a Pass result
         # return to the defaults
         self.SN_field.delete("1.0", "end")
         self.HwVer_field.delete("1.0", "end")
         self.button2.config(bg=color)
    else:
         self.button2.config(bg='red2')
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Bryan Oakley    6 年前

    after . 这将允许事件循环继续处理事件(包括导致显示刷新的事件)。

    例如:

    def reset(self):
        self.SN_field.dellete("1.0", ,"end")
        self.HwVer_field.delete("1.0", "end")
        self.button2.config(bg=color)
    

    之后 :

    if condition1 == condition2:
        orig_color = self.button2.cget("background")
        self.button2.config(bg='springgreen2')
        self.return2default(orig_color)
        self.after(3000, self.reset) 
    

    之后