Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- window = Tk()
- window.title('Questionnaire')
- window.geometry('400x200')
- questions = [
- (),
- ("Question 1: Do you like Python?", 2, 3),
- ("Question 2: Do you prefer cats over dogs?", 3, 4),
- ("Question 3: Are you a morning person?", 5, 7),
- ("Question 4: Do you enjoy reading books?", 6, 9),
- ("Question 5: Is pizza your favorite food?", 8, 9),
- ("Question 6: Do you like traveling?", 9, 10),
- ("Question 7: Are you interested in learning new languages?", 5, 10),
- ("Question 8: Do you enjoy outdoor activities?", 6, 10),
- ("Question 9: Are you a fan of superhero movies?", 4, 10),
- ("Question 10: Do you like solving puzzles?", 0, 0)
- ]
- question_index = 1
- yesnum = 0
- nonum = 0
- def go():
- global question_index, yesnum, nonum, question_label
- data = questions[question_index]
- quest = data[0]
- yesnum = data[1]
- nonum = data[2]
- question_label = Label(window, text=quest) # text=self.questions[self.current_question_index])
- question_label.pack()
- yes_button = Button(window, text="YES", command=next_yes)
- yes_button.pack(side=LEFT, padx=10)
- no_button = Button(window, text="NO", command=next_no)
- no_button.pack(side=RIGHT, padx=10)
- def next():
- global question_index, yesnum, nonum, question_label
- if question_index == 0:
- question_label.config(text="Questionnaire completed.")
- else:
- data = questions[question_index]
- quest = data[0]
- yesnum = data[1]
- nonum = data[2]
- question_label.config(text=quest)
- def next_yes():
- global question_index, yesnum
- question_index = yesnum
- next()
- def next_no():
- global question_index, nonum
- question_index = nonum
- next()
- go()
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment