0

so I want to add a typewriter effect to on the button text not that the button activates a function that types a word and also on label text I don't know how I tried some but they are mostly for when you press a button that it types out text I want the typing effect on the button and label text like in the Watson Scott test. my code so far:

from ast import Return
from cgitb import text
from tkinter import *
import sys
import os
from time import sleep


win = Tk()

win.config(bg = "black")
win.attributes('-fullscreen',True)

play_count = 1
question_num = 1

def resource_path(relative_path):
    try:
        base_path = sys._MEIPASS
    except Exception:
        base_path = os.path.abspath(".")

    return os.path.join(base_path, relative_path)

def da():
    global question_num
    if question_num==1 :
        pitanje_menu.config(text="dali osjetiš da te netko promatra?")
    elif question_num==2 :
        pitanje_menu.config(text="dali možeš trčati brže od normalnog čovjeka?")
    elif question_num==3 :
        pitanje_menu.config(text="dali prepoznaješ osobu iza tebe?") 
            
    else:
        return    
    question_num+=1

def ne():
    global question_num
    if question_num==1 :
        pitanje_menu.config(text="dali znaš neke vještine za samo obranu?")
    elif question_num==2 :
        pitanje_menu.config(text="dali je daleka policijska stanica ili bolnica?")
    elif question_num==3 :
        pitanje_menu.config(text="dali prepoznaješ osobu iza tebe?")    
    else:
        return    
    question_num+=1


def play():
    global play_count
    if play_count==1 :
        pitanje_menu.config(text="jesi li sam?", font= ('Open Sans', 50))
        da_play.config(text="da", command=da)
        da_play.place(x= "640", y= "490", anchor=CENTER)
        ne_gumb = Button(win, text="ne", bg="black", fg="white", font= ('Open Sans', 60), borderwidth=0, command=ne)
        ne_gumb.place(x= "870", y= "490", anchor=CENTER)

    elif play_count==2:
        pitanje_menu.config(text="ako ti uđem u kuću dali bi trčao?")
    else:
        return 
    play_count+=1

    


exit_gumb= Button(win, text="EXIT", command=win.destroy)
exit_gumb.place(x="1450", y="0")
exit_gumb.config(fg="white", bg="black", font= ('Open Sans', 20), borderwidth=0)
pitanje_menu = Label(win, text="The Game", bg="black", fg="white", font= ('Open Sans', 40))
pitanje_menu.place(x= "770", y= "240", anchor=CENTER)
da_play = Button(win, text="play", bg="black", fg="white", font= ('Open Sans', 60), borderwidth=0, command=play)
da_play.place(x= "770", y= "490", anchor=CENTER)








win.mainloop()
Talha Tayyab
  • 8,111
  • 25
  • 27
  • 44
  • Where is the code part that deals with your typewriter effect? What did you try so far? – Module_art Mar 31 '22 at 15:05
  • i tried this words = "Typing effect in tkinter.py" ab=StringVar() a=Label(textvariable=ab) a.pack() for i in words: a=ab.get() ab.set(a+i) root.after(1000) root.update() root.mainloop() – grozan programer Mar 31 '22 at 15:40

0 Answers0