I have a script that has a Tkinter module in it that i would like to change the background color in 3min intervals e.g green for 3mins then orange then red. I have the code to display the green but can't get it to change.
When I make a function in my code it gets a few different errors including 'root not defined, global name "root" no defined' although it is.
Also on a side note kill the Tk display after 15 mins so once all 3 colours have been though.
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
I have also tried
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
If I place root = Tk() anywhere else I get a small gray TK box that I don't want.
P.S I know that it's set to 10 seconds that's only so I can test it
afteris in milliseconds.