Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_color_substr.py
- import Tkinter as tk
- root = tk.Tk()
- c = tk.Canvas(root)
- c.pack(expand=1, fill=tk.BOTH)
- words = '''This is a demo program that involves displaying some text in a box via its Tkinter canvas, within a loop. Each word is displayed then replaced by the next sort of like flash cards. One letter of each word, close to the middle of the word, so that when a person is reading the words their eyes focus on the middle of each word'''
- words = words.split()
- def new_word(i):
- if i == len(words):
- i = 0
- word = words[i]
- if not word[-1].isalnum():
- word = word[:-1]
- middle = (len(word)+1)//2
- c.itemconfigure(t1, text=word[:middle-1]+' ')
- c.itemconfigure(t2, text=word[middle-1:middle])
- c.itemconfigure(t3, text=word[middle:])
- root.after(200, lambda: new_word(i+1))
- tt = ("Courier", 40, 'bold')
- t1 = c.create_text(200,100,text='', anchor='e', font=tt, fill='darkgray')
- t2 = c.create_text(200,100,text='', anchor='e', font=tt, fill='darkorange')
- t3 = c.create_text(200,100,text='', anchor='w', font=tt, fill='darkgray')
- new_word(0)
- root.geometry('400x200+200+200')
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement