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

  • SEARCH
  • Home
  • 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 7762019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:17:02+00:00 2026-06-01T14:17:02+00:00

I am making a menu test for the employees at my restaurant. The plan

  • 0

I am making a menu test for the employees at my restaurant. The plan is for menu items to loop through “Loop items here” at which time they select the correct checkbuttons (ingredients) and then click the “submit and continue button“. When they click the submit button I first need to read the on and off values of the checkbuttons to determine which items they have selected, then compare those to the correct answers that I defined in a dictionary of lists, then clear all checkbuttons and whether the answer is wrong or right the program will continue on and I will eventually have a results screen but right now I am stuck on how to read the checkbutton on and off values. I am simply trying to print the selected veggies right now and cant figure it out.

I think it has to do with the fact they are in different methods and also the fact that they were added in a loop? I am not sure exactly but I know my code is trying to read the wrong thing and any help would be greeeeatly appreciated!

Sorry for the lengthy question I just thought it would be beneficial to give you as much info as possible to understand what I am trying to do..

screenshoot

from tkinter import *

class GUI(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.parent = parent
        self.initUI()

    def initUI(self):
        self.grid()
        self.parent.title("Wahoos Menu Test")
        self.create_buttons()

    global count
    count = -1

    def create_buttons(self):
        for r in range(20):
            for c in range(14):
                Label(self, text='',
                    borderwidth=0).grid(row=r,column=c)
        B = Button(self, text ="Begin Exam", relief=RIDGE, fg="black", command= self.on_button_press).grid(row=19, column=7)
        L = Label(self, text="What comes in the following", fg="blue").grid(row=6, column=0)
        self.veg = ['Lettuce', 'Cabbage', 'Cheese', 'Ahee Rice', 'Brown Rice', 'Banzai Veg', 'Red Cabbage', 'Black Beans', 'Cajun White Beans']
        self.vegboxes = []
        self.opt = []
        c = 1
        for ve in self.veg:
            c +=1
            self.v = IntVar()
            self.vegboxes.append(self.v)
            vo = Checkbutton(self, text=ve, variable=self.v, onvalue=1, offvalue=0).grid(row=c, column=11, sticky=W)

    def on_button_press(self):
        global count
        count = count + 1
        menuItems = {'nft': ['cabbage', 'cheese', 'corn', 'nf', 'salsa'],
        'nckt': ['lettuce', 'cheese', 'corn', 'nck', 'salsa']}
        menu = ['blackened fish taco', 'wahoos chicken salad']
        if count == len(menu):
            C = Button(self, text ="           Your Done!          ", relief=RIDGE, fg="black").grid(row=19, column=7)
        else:
            m = Label(self, text=menu[count], fg="black").grid(row=7, column=0)
            C = Button(self, text ="Submit and Continue", relief=RIDGE, fg="black", command= self.read_checks).grid(row=19, column=7)
    def read_checks(self):
        for v in self.veg:
            if self.v == 1:
                print(self.veg[v])


def main():
    root = Tk()
    app = GUI(root)
    root.mainloop()

if __name__ == '__main__':
    main()
  • 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-01T14:17:03+00:00Added an answer on June 1, 2026 at 2:17 pm

    You could create a dictionary and have each key be the Checkbutton’s label,
    and have the value be the state “Control Variable”.
    Then you would check the state with the Control Variable’s get() method as shown in the example below.

    import tkinter as tk
    
    class GUI(tk.Tk):
        def __init__(self):
            tk.Tk.__init__(self)
    
            self.buttonDic = {
            'Brown Rice':0,
            'Banzai Veg':0,
            'Red Cabbage':0,
            'Black Beans':0
            }
    
            for key in self.buttonDic:
                self.buttonDic[key] = tk.IntVar()
                aCheckButton = tk.Checkbutton(self, text=key,
                                                variable=self.buttonDic[key])
                aCheckButton.grid(sticky='w')
    
            submitButton = tk.Button(self, text="Submit",
                                            command=self.query_checkbuttons)
            submitButton.grid()
    
        def query_checkbuttons(self):
            for key, value in self.buttonDic.items():
                state = value.get()
                if state != 0:
                    print(key)
                    self.buttonDic[key].set(0)
    
    gui = GUI()
    gui.mainloop()
    

    This approach allows you to create and analyze the Checkbuttons with one dictionary.
    Note the use of items() in for key, value in self.buttonDic.items():
    which is needed to prevent:
    ValueError: too many values to unpack

    More information on the Checkbutton widget and it’s variable can be found: here


    I’m going to include my first attempt which was based on
    the Checkbutton widget’s onvalue and offvalue,
    in case it helps someone understand Control Variables a bit more.

    import tkinter as tk
    
    class GUI(tk.Tk):
        def __init__(self):
            tk.Tk.__init__(self)
    
            self.bRiceV = tk.StringVar()
            bRice = tk.Checkbutton(self, text="Brown Rice",variable=self.bRiceV,
                                        onvalue="Brown Rice", offvalue="Off")
            bRice.pack()
    
            self.bVegV = tk.StringVar()
            bVeg = tk.Checkbutton(self, text="Banzai Veg",variable=self.bVegV,
                                        onvalue="Banzai Veg", offvalue="Off")
            bVeg.pack()
    
            self.varList = [self.bRiceV, self.bVegV]
    
            submitButton = tk.Button(self, text="Submit",
                                    command=self.query_checkbuttons)
            submitButton.pack()
    
        def query_checkbuttons(self):
            for var in self.varList:
                value = var.get()
                if value != 'Off':
                    print(value)
                    var.set('Off')
    
    gui = GUI()
    gui.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a menu with <ul> / <li> and CSS. Here's what I have
I'm making a pure css dropdown menu (code here: http://jsfiddle.net/SeXyv/7/ ) and I would
Is there a built-in Android icon for open or load? I'm making menu items,
I am making a menu which has three parts to it: Menu links left
I was making a menu with id menu which had the following set: display:
I am making a dropdown menu and am trying to make the list items
I am making a menu for an app and was pointed to this useful
I'm pretty new to HTML and CSS. I'm making a menu bar horizontal and
I am making a css menu. For this I am using a ul .
I'm making a game and in the menu I want to display the text

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.