We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,617 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Color changing window demo of tkinter after timer events

0
By Tony Veijalainen on Sep 25th, 2011 10:36 pm

This is one small snippet of after event usage. You could express if you find this kind of simple code to be usefull as snippet. Notice also vegaseat's sticky message threads in begining of Python forum in addition to code snippets.

# originally posted in thread http://www.daniweb.com/software-development/python/threads/298190/1282328#post1282328
try:
    from Tkinter import *
except:
    from tkinter import *

def change(a=0):
    color_label.config(bg = "blue" if a & 1 else "purple")
    color_label.after(400,change, a ^ 1 )

if __name__ == '__main__':
    win = Tk() 
    win.geometry("500x300")
    win.title('Demonstrating after event')
    color_label = Label(win)
    color_label.pack(expand=YES, fill=BOTH)
    change()
    
    win.mainloop()

A question on the topic of background colors, is there a way to make an entire Frame's background white, including unassigned space? And, without getting those nasty grey areas around labels and windows?

pyguy62
Posting Whiz
353 posts since Aug 2011
Reputation Points: 34
Solved Threads: 19
Skill Endorsements: 0

re: pyguy62: Only by putting bg='white' everywhere, tk, I do not know ttk themes:

try:
    from Tkinter import *
except:
    from tkinter import *

if __name__ == '__main__':
    win = Tk() 
    win.geometry("500x300")
    win.title('Demonstrating bg')
    win.config(bg='white')
    color_frame = Frame(bg='white')
    Label(win, bg='white', text='test').pack()
    color_frame.pack(expand=YES, fill=BOTH)
    
    win.mainloop()
pyTony
pyMod
Moderator
6,330 posts since Apr 2010
Reputation Points: 879
Solved Threads: 989
Skill Endorsements: 27

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0633 seconds using 2.8MB