Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9020105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:55:59+00:00 2026-06-16T04:55:59+00:00

I want to write a program that asks the user a series of questions

  • 0

I want to write a program that asks the user a series of questions in different dialog boxes. Each box shows up one at a time, and goes to the next box if the button next is clicked. My question is do I create a class for each Dialog and just call the next class once the button next is clicked? Or is there a more elegant solution to this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:56:01+00:00Added an answer on June 16, 2026 at 4:56 am

    My recommendation is to build a base class that holds the current question, then when the user answers a question and advances to the next one, the base class updates the display of the new current question. You don’t need to destroy widgets at any point (except when quitting the application), and you can also reuse widgets before creating new ones.

    Let me simplify the format of your questions to this one: each question contains a question description and a set of answers where the user can pick a single one. These simplifications can be removed, but I set them in order to present an initial code to deal with the problem.
    Here is a starting point for doing exactly this (my imagination towards naming was weak):

    import random
    import Tkinter
    import ttk
    
    # Make 5 "questions" with varied number of answers to pick from.
    QUESTION = [u"Question %d" % (i + 1) for i in range(5)]
    QOPTS = []
    k = 1
    for _ in QUESTION:
        num_opts = random.randint(3, 6)
        QOPTS.append([u"text %d" % (k + i) for i in range(num_opts)])
        k += num_opts
    
    
    class Question:
        def __init__(self, master):
            self._common_var = Tkinter.StringVar()
    
            self._title = None
            self._lframe = None
            self._rb = []
            self._make_gui(master)
    
        def get_answer(self):
            return self._common_var.get()
    
        def reset_answer(self):
            self._common_var.set("")
    
        def _make_gui(self, master):
            self._title = ttk.Label(master, padding=(0, 6, 0, 0))
            self._title.grid(in_=master, padx=6, row=0, column=0, sticky='ew')
    
            self._lframe = ttk.Labelframe(master)
            self._lframe.grid(in_=master, padx=6, row=1, column=0, sticky='nsew')
    
        def update_gui(self, question, options):
            self._title['text'] = question
            for i, opt in enumerate(options):
                if i < len(self._rb):
                    if not self._rb[i].grid_info():
                        self._rb[i].grid()
                    self._rb[i]['text'] = opt
                else:
                    rb = ttk.Radiobutton(self._lframe, text=opt, value=i,
                            variable=self._common_var)
                    rb.grid(in_=self._lframe, row=i, column=0, sticky='w')
                    self._rb.append(rb)
            # Deal with i < total.
            for k in xrange(i + 1, len(self._rb)):
                self._rb[k].grid_remove()
    
    
    
    class Base:
        def __init__(self, frame, q, o):
            self.master = frame
    
            self.question = None
            self.curr_question = 0
            self.q = q
            self.o = o
            self._make_gui(frame)
            self._update_gui()
    
        def next_question(self):
            answer = self.question.get_answer()
            try:
                answer = int(answer)
            except ValueError:
                print "Question not answered, stay here."
                return
            print "Answer for question %d: %d" % (self.curr_question, answer)
            self.question.reset_answer()
    
            self.curr_question += 1
            self._update_gui()
    
        def _make_gui(self, frame):
            self.question = Question(frame)
            frame.columnconfigure(0, weight=1)
            frame.rowconfigure(1, weight=1)
    
            btn = [(u"Next", self.next_question)]
            self._btn = []
            for i, (text, cmd) in enumerate(btn):
                # Assumption: the Question instance always uses the rows 0 and 1.
                b = ttk.Button(frame, text=text, command=cmd)
                b.grid(in_=frame, padx=6, pady=6, row=2, column=i, sticky='e')
                self._btn.append(b)
    
        def _update_gui(self):
            if self.curr_question == len(self.q):
                print "Done"
                self.master.quit()
                return
            elif self.curr_question == len(self.q) - 1:
                for btn in self._btn:
                    # No next question
                    btn['text'] = u"Finish"
    
            self.question.update_gui(self.q[self.curr_question],
                    self.o[self.curr_question])
    
    
    root = Tkinter.Tk()
    root.columnconfigure(0, weight=1)
    root.rowconfigure(0, weight=1)
    root.geometry('300x250')
    frame = ttk.Frame(root)
    frame.grid(sticky='nsew')
    Base(frame, QUESTION, QOPTS)
    root.mainloop()
    

    And here is the GUI you will get:

    enter image description here enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a program that shows one PC's screen to the others...
I want to write a program in C or C++ that asks to user
I want to write a program that allows user to select one SQL Server
Trying to write a program that asks the user if they want instructions. If
I want to write a program that sets cold to true if the user
I want to write a java program that acts as a user interface to
I want to write a simple program that determines whether the number the user
Hello I am trying to write a program in python that asks the user
I want to write a program that sends an e-mail to one or more
I want to write a program that deletes duplicate iTunes music files. One approach

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.