Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- class QuestionnaireApp(tk.Tk):
- def __init__(self):
- super().__init__()
- self.title("Questionnaire")
- self.geometry("400x200")
- self.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)
- ]
- self.current_question_index = 1
- self.data = self.questions[self.current_question_index]
- self.quest = self.data[0]
- self.yesnum = self.data[1]
- self.nonum = self.data[2]
- self.question_label = tk.Label(self, text=self.quest) # text=self.questions[self.current_question_index])
- self.question_label.pack()
- self.yes_button = tk.Button(self, text="YES", command=self.next_yes)
- self.yes_button.pack(side=tk.LEFT, padx=10)
- self.no_button = tk.Button(self, text="NO", command=self.next_no)
- self.no_button.pack(side=tk.RIGHT, padx=10)
- def next_yes(self):
- self.current_question_index = self.yesnum
- if self.current_question_index == 0:
- self.question_label.config(text="Questionnaire completed.")
- else:
- self.data = self.questions[self.current_question_index]
- self.quest = self.data[0]
- self.yesnum = self.data[1]
- self.nonum = self.data[2]
- self.question_label.config(text=self.quest)
- def next_no(self):
- self.current_question_index = self.nonum
- if self.current_question_index == 0:
- self.question_label.config(text="Questionnaire completed.")
- else:
- self.data = self.questions[self.current_question_index]
- self.quest = self.data[0]
- self.yesnum = self.data[1]
- self.nonum = self.data[2]
- self.question_label.config(text=self.quest)
- if __name__ == "__main__":
- app = QuestionnaireApp()
- app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement