【发布时间】:2015-05-13 10:12:56
【问题描述】:
我有一个脚本,其中包含一个 Tkinter 模块,我想以 3 分钟的间隔更改背景颜色,例如绿色 3 分钟,然后橙色然后红色。 我有显示绿色的代码,但无法更改。
当我在我的代码中创建一个函数时,它会出现一些不同的错误,包括 'root 未定义,全局名称 "root" 未定义' 虽然它是。
另外,在 15 分钟后关闭 Tk 显示,所以一旦所有 3 种颜色都已完成。
from __future__ import absolute_import
from . import BasePlugin
import os, sys
import time
from Tkinter import *
def Orange (*args,**kwargs):
root.config(background="Orange")
def Red(*args,**kwargs):
root.config(background="Red")
class dis(BasePlugin):
def execute(self, msg, unit, address, when, printer, print_copies):
mseg = str('%s - %s' % (msg, unit))
root = Tk()
root.title('label')
txt = Label(root, font= 'times 20 bold', bg='Green')
txt.config(text= mseg)
txt.pack(fill=BOTH, expand=0)
root.after(10,Orange)
root.after(10,Red)
root.mainloop(0)
PLUGIN = dis
我也试过了
from __future__ import absolute_import
from . import BasePlugin
import os, sys
import time
from Tkinter import *
def Orange (*args,**kwargs):
txt.config(background="Orange")
def Red(*args,**kwargs):
txt.config(background="Red")
class dis(BasePlugin):
def execute(self, msg, unit, address, when, printer, print_copies):
mseg = str('%s - %s' % (msg, unit))
root = Tk()
root.title('label')
txt = Label(root, font= 'times 20 bold', bg='Green')
txt.config(text= mseg)
txt.pack(fill=BOTH, expand=0)
txt.after(10,Orange)
txt.after(10,Red)
root.mainloop(0)
PLUGIN = dis
如果我将root = Tk() 放在其他任何地方,我会得到一个我不想要的灰色小盒子。
P.S 我知道它设置为 10 秒,只是为了测试它
【问题讨论】:
-
当前设置为 10 毫秒,而不是 10 秒。
after的参数以毫秒为单位。
标签: python tkinter tk tkinter-canvas