我有什么办法可以在Tkinter中实现标签背景的两种颜色之间的淡入?我想让我的计时器的标签颜色在倒计时时改变。这些是我目前正在处理的片段(以澄清我在做什么)。在
…
labelcolor = "#%02x%02x%02x" % (0, 0, 0)
…
def pomodoro(self, remaining = None):
self.button.configure(state=tk.DISABLED)
self.labelcolor = "#%02x%02x%02x" % (200, 32, 32)
self.label.configure(bg = self.labelcolor)
if remaining is not None:
self.remaining = remaining
if self.remaining <= 0:
self.label.configure(text="Time's up!")
self.breakcommand
else:
self.label.configure(text= time.strftime('%M:%S', time.gmtime(self.remaining))) #Integer to 'Minutes' and 'Seconds'
self.remaining = self.remaining - 1
self.after(1000, self.pomodoro)
…
self.label = tk.Label(self, text="Pick One", width=12, font="Helvetica 32", fg = "white", bg = self.labelcolor )
…
这里有一个小代码,我一起创建了一个渐变色条。我不知道这对你是否有用,但是…它起作用了。。。在
^{1}$当然,您可能希望在矩形上保留一个句柄,以便以后可以更改颜色,而且您可能也可以更有效地执行此操作,但这可能是一个很好的起点。在
编辑
^{pr2}$这在课堂上会干净很多,但希望你能理解。在
相关问题 更多 >
编程相关推荐