【发布时间】:2016-10-23 14:51:05
【问题描述】:
这里是 Python 初学者。
我需要一种在 Python 中显示颜色序列的方法,我选择使用 Tkinter。
我设法拥有一个 Button 并使其在单击时更改其背景颜色,但是当我进行多项更改时,仅呈现最后一个。
我几乎可以肯定这不是 Tkinter 本身的问题,而是 Python 本身处理函数的方式,所以这可能已经在这里讨论过了,但作为一个初学者,我真的不知道该寻找什么。我猜正确的关键字就足够了。
from Tkinter import *
import time
class App:
def __init__(self, master):
self.slogan = Button(command=self.change)
self.slogan.pack()
def change(self):
self.slogan.configure(bg = 'red')
time.sleep(1)
self.slogan.configure(bg = 'blue')
root = Tk()
app = App(root)
root.mainloop()
此代码应该在单击时将颜色更改为红色,等待并将颜色更改为蓝色,而不是将颜色更改为蓝色。
【问题讨论】: