Saturday, October 24, 2020

Rolling text animation with Python

Logo.gif

from tkinter import *
from random import randint
from time import sleep

win = Tk()
win.geometry("750x500+0+0")

S00, S01, S02, S03, S04 = StringVar(), StringVar(), StringVar(), StringVar(), StringVar()
S05, S06, S07, S08, S09 = StringVar(), StringVar(), StringVar(), StringVar(), StringVar()
S10, S11, S12, S13, S14 = StringVar(), StringVar(), StringVar(), StringVar(), StringVar()
X, Y = 200, 13

lbl = Label(win, text = "", bg="black", fg="yellow", width=18, font=("Helvetica", 36, "bold"));    lbl.place(x=X-22, y=Y)
lbl00 = Label(win, textvariable = S00, bg="black", fg="#FFFF00", font=("Helvetica", 36, "bold"));  lbl00.place(x=X, y=Y)
lbl01 = Label(win, textvariable = S01, bg="black", fg="yellow", font=("Helvetica", 36, "bold"));   lbl01.place(x=X+40, y=Y)
lbl02 = Label(win, textvariable = S02, bg="black", fg="yellow", font=("Helvetica", 36, "bold"));   lbl02.place(x=X+80, y=Y)
lbl03 = Label(win, textvariable = S03, bg="black", fg="yellow", font=("Helvetica", 36, "bold"));   lbl03.place(x=X+125, y=Y)

lbl04 = Label(win, textvariable = S04, bg="black", fg="yellow", font=("Helvetica", 36, "bold"));   lbl04.place(x=X+160, y=Y)
lbl05 = Label(win, textvariable = S05, bg="black", fg="yellow", font=("Helvetica", 36, "bold"));   lbl05.place(x=X+200, y=Y)
lbl06 = Label(win, textvariable = S06, bg="black", fg="yellow", font=("Helvetica", 36, "bold"));   lbl06.place(x=X+240, y=Y)
lbl07 = Label(win, textvariable = S07, bg="black", fg="yellow", font=("Helvetica", 36, "bold"));   lbl07.place(x=X+280, y=Y)

lbl08 = Label(win, textvariable = S08, bg="black", fg="yellow", font=("Helvetica", 36, "bold"));   lbl08.place(x=X+358, y=Y)
lbl09 = Label(win, textvariable = S09, bg="black", fg="yellow", font=("Helvetica", 36, "bold"));   lbl09.place(x=X+398, y=Y)
lbl10 = Label(win, textvariable = S10, bg="black", fg="yellow", font=("Helvetica", 36, "bold"));   lbl10.place(x=X+438, y=Y)
lbl11 = Label(win, textvariable = S11, bg="black", fg="yellow", font=("Helvetica", 36, "bold"));   lbl11.place(x=X+460, y=Y)

pic1 = PhotoImage(file="Logo.gif")
lblLogo = Label(win, image=pic1);  lblLogo.place(x=50, y=0)

def roll(S, ch, lbl):
  for i in range(16):
    S.set(chr(65 + randint(0, 25)))
    sleep(.01)
    win.update_idletasks()
    S.set("   ")
    cols = ["#000000", "#111100", "#222200", "#333300",
            "#444400", "#555500", "#666600", "#777700",
            "#888800", "#999900", "#AAAA00", "#BBBB00",
            "#CCCC00", "#DDDD00", "#EEEE00", "#FFFF00"
           ]
    lbl.config(fg=cols[i])
  S.set(ch)

roll(S00, 'C ', lbl00);  roll(S01, 'O ', lbl01)
roll(S02, 'M ', lbl02);  roll(S03, 'P ', lbl03)
roll(S04, 'U ', lbl04);  roll(S05, 'T ', lbl05)
roll(S06, 'E ', lbl06);  roll(S07, 'R ', lbl07)
roll(S08, 'Q ', lbl08);  roll(S09, 'U ', lbl09)
roll(S10, 'I ', lbl10);  roll(S11, 'Z ', lbl11)

win.mainloop()

Thursday, October 8, 2020

Independence Day Quiz (tkinter)

 


 0.png
 2.png
 4.png

 6.png


from tkinter import *

win = Tk()
win.geometry("1000x650")

ctr, I = 0, IntVar()
QList = ["Who said 'Freedom is my birthright and I shall have it'?",
         "This is Bharat Mata, 1905; the first instance of the concept of Bharat Mata appearing in art. Identify the painter.",
         "Who said 'Give me your blood and I shall give you freedom'?",
         "Our national flag was modified several times during the freedom movement. Identify the flag used during the Swadeshi Movement of 1906.",
         "Who announced the permission to have full self-government to British India?",
         "This train station sign board is in Tamil Nadu, in remembrance to the freedom fighter and revolutionary Vanchi Maniachi Vanchinatha Iyer, popularly known as Vanchi. Who did he assassinate? . Who was Robert William Ashe?",
         "Who was the last Governor-General of India?",
         "The Indian Independence Act was repealed in which article of the Constitution of India?",
         "An announcement of a Malayalam movie based on the life of a freedom fighter from Malapuram was done recently causing a lot of backlash to the director and actor. Whose biopic is it?",
         "The Indian Muslim Movement was led by ...",
         "Which battle is said to be the most important one for the East India Company?",
         "By law, what type of cloth material is used for making national flag?",
         '''
         "Who designed the present Triranga (tricolor) national flag?",
         "Who is known as Kerala Gandhi?",
         "Which famous freedom fighter was known as 'Bharatha Kokila' or the Nightingale of Indai?",
         "Which act introduced by British authorized the government to imprison any person suspected of terrorism for up to two years without trial?",
         "Which Act expanded the participation of Indians in the government?",
         "Who carried out the partition of Bengal?",
         "Who was the Law Minister in the 1st Indian government headed by Jawaharlal Nehru ministry of 1947?",
         "At the Lahore Session of the Indian National Congress, the tri-colour was unfurled for the first time.Which year was that?",
         "The First Indian National Army was founded by?",
         "Which of the following is not a part of protest against salt tax?",
         "Who set up the Indian Independence League?",
         "The first weekly paper published by the Indian National Congress in 1889?",
         "Where was the Civil disobedience movement launched in1922?",
         "Where did the Congress Working committee first accept the idea of the Quit India Movement?", 
         "When did Gandhiji start the Sabarmati Ashram?",
         "What is the nick name of the English East India Company?",
         '''
        ]

AList = [["a. Lala Lajpat Rai",           "b. Bal Ganga Dhar Tilak",      "c. Bipin Chandra Pal",          "d. Netaji Subhas Chandra Bose", 2, "b. Bal Ganga Dhar Tilak"],
         ["a. Raveendranatha Tagore",     "b. Abaneedranath Tagore",      "c. Nandalal Bose",              "d. Amritha Shergil",            2, "b. Abaneedranath Tagore"],
         ["a. Bal Ganga Dhar Tilak",      "b. Bipin Chandra Pal",         "c. Netaji Subhas Chandra Bose", "d. Lala Lajpat Rai",            3, "c. Netaji Subhas Chandra Bose"],
         ["a. Clement Attlee",            "b. Louis Mountbatten",         "c. Lord Dalhousie ",            "d. Lord Wavell",                2, "b. Louis Mountbatten"], 
         ["a. Lord Wavell",               "b. Lord Willingdon",           "c. Lord Mountbatten",           "d. James Brown",                4, "d. James Brown"], 
         ["a. Robert Ashe, tax colletor", "b. Charles Tegart, policeman", "c. John Nicholson, armyman",    "d. Lord Mayo, Viceroy.",        1, "a. Robert Ashe, tax colletor"],
         ["a. Article 221",               "b. Article 144",               "c Article 395",                 "d. Article 345",                4, "d. Article 345"],
         ["a. Kunjahammed Haji",          "b. Abdur Rahiman",             "c. Moidu Moulavi",              "d. Abdul Rahim",                1, "a. Kunjahammed Haji"],
         ["a. Muhammad Ali Jinnah",       "b. Shaukat Ali",               "c. Maulana Azad",               "d. Rehamt Ali",                 2, "b. Shaukat Ali"],
         ''' 
         ["a. Capture of Lucknow", "b. Battle of Plassey", "c. Battle of Phillora", "d. Battle of Panipat", 2],
         ["a. Khadi cloth", "b. Cotton cloth", "c. Naylon cloth", "d. Jute cloth", 1],
         ["a. Mahatma Gandhi", "b. Pingalivenkayya", "c. Surayya Tyabji", "d.Panduranga Reddy",2],
         ["a. Abdul Gafoor Khan", "b. Ayyankali", "c. K. Kelappan", "d. Sree Narayana Guru", 3],
         ["a. Sarojini Naidu", "b. Lala Lajpat Rai", "c. Laxmi bai", "d. Abdul Gafoor Khan", 1],
         ["a. Charter Act", "b. Rowlatt Act", "c.Defence of India Act", "d. Salt Act", 2],
         ["a. Govt. of India Act,1909", "b. Govt. of India Act,1919", "c. Govt. of India Act,1935", "d. Govt. of India Act,1996", 2], 
         ["a. Lord Curzon", "b. Lord Dufferin", "c. Lord Minto", "d. James Broun", 1],
         ["a. C.D.Deshmukh", "b. Baldev Singh", "c. John Mathai", "d. B.R.Ambedkar", 4],
         ["a. 1929", "b. 1931", "c. 1927", "d. 1926", 1],
         ["a. Bhagat Singh", "b. Capt.Mohansingh", "c. Subhash Chandra Bose", "d.Wallabhai Patel", 2],
         ["a. Dandi Satyagraha", "b. Dharasana Satyagraha", "c. Non-Cooperation Movement", "d. Mahatma Gandhi", 3], 
         ["a. Rash Bihari Bose", "b. Baldev Singh", "c. C.D.deshmukh", "d. Ghan Abdul", 1],
         ["a. Hindi Akhbar", "b. Voice of India", "c. Marathi Samachar", "d. India Times", 2],
         ["a. Bihar", "b. Champaran", "c. Lucknow", "d. Bardoli", 4],
         ["a. Wardha", "b. Sabarmati", "c. Bardoli", "d. Champaran", 1],
         ["a. 1915", "b. 1916", "c. 1920", "d. 1918", 2],
         ["a. William Company", "b. James Company", "c. John Company", "d. Clement Company", 3]
         '''
        ]

def Next():
  global ctr
  lblVerdict.config(text="")
  rbtnA1.place(x=110, y=240);  rbtnA2.place(x=110, y=280)
  rbtnA3.place(x=110, y=320);  rbtnA4.place(x=110, y=360)
  btnStart.config(state=DISABLED);  btnNext.config(state=DISABLED);  btnCheck.config(state=NORMAL)
  
  msgQNo.config(text="Q " + str(ctr+1))
  msgQues.config(text=QList[ctr])
  rbtnA1.config(text=AList[ctr][0]);  rbtnA2.config(text=AList[ctr][1])
  rbtnA3.config(text=AList[ctr][2]);  rbtnA4.config(text=AList[ctr][3])
  
  ctr += 1
  rbtnDum.select()
  lblCorrAns.config(text="")

  if ctr == 2 or ctr == 4 or ctr == 6:
    pic = PhotoImage(file=str(ctr) + ".png")
    lblImage.config(image=pic)
    lblImage.image = pic
  else:
    pic = PhotoImage(file="0.png")
    lblImage.config(image=pic)
    lblImage.image = pic

def Check():
  print(I.get())
  if I.get() == AList[ctr-1][4]:
    lblVerdict.config(text="Correct", fg="blue")
    print(AList[ctr-1][5])
  else:
    lblVerdict.config(text="Incorrect", fg="red")
    s = AList[ctr-1][5]
    print(s)              
    lblCorrAns.config(text=s, fg="blue")
  btnCheck.config(state=DISABLED);  btnNext.config(state=NORMAL)

  if ctr == len(QList):
    btnNext.config(state=DISABLED)

msgQNo    = Message(win, font=("Arial", 20, "bold"), width=75);     msgQNo.place(x=10, y=20)
msgQues   = Message(win, font=("Arial", 20, "bold"), width=650);    msgQues.place(x=100, y=20)

picStart = PhotoImage(file="Start.png")
btnStart = Button(win, command=Next, image=picStart);  btnStart.place(x=100, y=415)

picNext = PhotoImage(file="Next.png")
btnNext = Button(win, command=Next, image=picNext, state=DISABLED);  btnNext.place(x=200, y=415)

picCheck = PhotoImage(file="Check.png")
btnCheck = Button(win, command=Check, image=picCheck, state=DISABLED);  btnCheck.place(x=300, y=415)

rbtnA1    = Radiobutton(win, font=("Arial", 14, "bold"), variable=I, value=1)
rbtnA2    = Radiobutton(win, font=("Arial", 14, "bold"), variable=I, value=2)
rbtnA3    = Radiobutton(win, font=("Arial", 14, "bold"), variable=I, value=3)
rbtnA4    = Radiobutton(win, font=("Arial", 14, "bold"), variable=I, value=4)
rbtnDum   = Radiobutton(win, font=("Arial", 10, "bold"), variable=I, value=5) 

lblImage = Label(win);  lblImage.place(x=450, y=150)

lblVerdict = Label(win, font=("Arial", 20, "bold"));  lblVerdict.place(x=200, y=540)
lblCorrAns = Label(win, font=("Arial", 20, "bold"));  lblCorrAns.place(x=370, y=540)

win.mainloop()