我有Python代码生成屏幕的平均颜色作为RGB值 and 十六进制代码 . 代码通过 while True
循环重复自身,我想在此循环结束时将指令更改为窗口颜色 .
我现在有这个代码:
from Tkinter import *
from colour import Color
root = Tk()
root.configure(background="grey")
root.geometry("400x400")
root.mainloop()
while True:
[ COLOUR GENERATING SCRIPT ]
hexcolour = Color(rgb=(red, green, blue))
root.configure(background=hexcolour)
有人可以告诉我如何启动Tkinter窗口,然后每次循环运行时更改颜色?
我正在为这个项目运行Python 2.7 .
1 回答
您需要完全删除
while
循环 . 相反,创建一个你将在循环中执行的函数,然后让该函数通过after
调用自身 . 然后它将运行程序的生命周期 .