python - I'm trying to print something letter by letter in a new window with tkinter import, but when I run it through the terminal the window doesn't pop up -
from tkinter import * import time while true: message in "hello world": time.sleep(.5) root = tk() lb = listbox(root, height=3) lb.pack() lb.insert(end, message) lb.insert(end,"second entry") lb.insert(end,"third entry") root.mainloop()
you have use root.after
call function add single letter, , use root.after
call same function add next letter.
from tkinter import * # --- functions --- def add_letter(text): if text: # if text not empty # add first letter text lb.insert(end, text[0]) # call again without first letter root.after(500, add_letter, text[1:]) # --- main --- root = tk() lb = listbox(root, height=15) lb.pack() # first call after 500ms root.after(500, add_letter, "hello world") root.mainloop()
edit: moving text :) using text
, reversed text
from tkinter import * # --- functions --- def add_letter(text): if text: # if text not empty # add first letter text lb.insert('1.0', text[0]) # put @ beginning of line # call again without first letter root.after(250, add_letter, text[1:]) # --- main --- root = tk() lb = text(root) lb.pack() text = ''.join(reversed("hello world of python , tkinter")) # first call after 250ms root.after(250, add_letter, text) root.mainloop()
Comments
Post a Comment