【问题标题】:how to make that every 10 sec automatically change the program background如何使每 10 秒自动更改程序背景
【发布时间】:2019-04-02 07:19:04
【问题描述】:

如何让每 10 秒自动改变程序背景 并且颜色会随机选择

color = (random.randint(0,255),random.randint(0,255),random.randint(0,255))  

更新:

我想在这段代码中使用:

app = wx.App()
window = wx.Frame(None, title = "test con", size=(800,300) ) 
window.SetMaxSize(wx.Size(800,300))
window.SetMinSize(wx.Size(800,300))
window.SetIcon(wx.Icon("eq.ico"))
window.SetBackgroundColour(color)
panel = wx.Panel(window, wx.ID_ANY)     
suka = bat()

def on_timer():
    label1aa.SetLabel(str(ram_uz()))
    label8.SetLabel(doi)
    label16.SetLabel(str(random.randint(1,100)))
    label1a.SetLabel(str(bat()))
    wx.CallLater(1000, on_timer)
panel.SetBackgroundColour(color)
panel.SetCursor(wx.Cursor(wx.CURSOR_HAND))

【问题讨论】:

  • module 'threading' has no attribute 'thread' 但它确实有一个 Thread 属性!注意大写T

标签: python-3.x wxpython


【解决方案1】:

试试这个希望对你有帮助

import threading
def change_color():
     while True:
          time.sleep(10)
          color = (random.randint(0,255),random.randint(0,255),random.randint(0,255))
threading.Thread(target=change_color).start()

【讨论】:

    【解决方案2】:

    你可以使用计时器:

    import threading
    
    timer = threading.Timer(interval, function) 
    //interval is the lapse of time you want between each execution of the function "function"
    timer.start()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多