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 7074619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:04:47+00:00 2026-05-28T06:04:47+00:00

I’ve been playing with combining entry widgets with tuples in python 2.7 tkinter. With

  • 0

I’ve been playing with combining entry widgets with tuples in python 2.7 tkinter. With this code, I should be able to enter the name of a fruit, search for it in the fruit bowl tuple, and if it’s in there, display the characteristics of that fruit using a set of radiobuttons.

from Tkinter import*

class Fruit:
    def __init__(self, parent):

        # variables
        self.texture_option = StringVar()
        self.climate_option = StringVar()

        # layout
        self.myParent = parent

        self.main_frame = Frame(parent, background="light blue")
        self.main_frame.pack(expand=YES, fill=BOTH)

        texture_options = ["Soft", "Crunchy","?"]
        climate_options = ["Temperate", "Tropical","?"]

        self.texture_option.set("?")
        self.climate_option.set("?")

        self.texture_options_frame = Frame(self.main_frame, borderwidth=3, background="light blue")
        self.texture_options_frame.pack(side=TOP, expand=YES, anchor=W)
        Label(self.texture_options_frame, text="Texture:", relief=FLAT, font="bold", background="light blue").pack(side=LEFT,anchor=W)
        for option in texture_options:
            button = Radiobutton(self.texture_options_frame, text=str(option), indicatoron=0,
            value=option, padx=5, variable=self.texture_option, background="light blue")
            button.pack(side=LEFT)

        self.climate_options_frame = Frame(self.main_frame, borderwidth=3, background="light blue")
        self.climate_options_frame.pack(side=TOP, expand=YES, anchor=W)
        Label(self.climate_options_frame, text="Climate:", relief=FLAT, font="bold", background="light blue").pack(side=LEFT,anchor=W)
        for option in climate_options:
            button = Radiobutton(self.climate_options_frame, text=str(option), indicatoron=0,
            value=option, padx=5, variable=self.climate_option, background="light blue")
            button.pack(side=LEFT)

        #search button
        self.search_frame = Frame(self.main_frame, borderwidth=5, height=50, background="light blue")
        self.search_frame.pack(expand=NO)

        enter = Entry(self.search_frame, width=30).pack(side=LEFT, expand=NO, padx=5, pady=5, ipadx=5, ipady=5)

        self.searchbutton = Button(self.search_frame, text="Search", foreground="white", background="blue",
        width=6, padx="2m", pady="1m")
        self.searchbutton.pack(side=LEFT, pady=5)
        self.searchbutton.bind("<Button-1>", self.searchbuttonclick)
        self.searchbutton.bind("<Return>", self.searchbuttonclick)


    def searchbuttonclick(self,event):
        #fruit  texture  climate 
        fruit_bowl=[
        ('Apple', 'Crunchy','Temperate'),
        ('Orange', 'Soft','Tropical'),
        ('Pawpaw','Soft','Temperate')]

        if enter.get()==fruit_bowl[x][0]:
            self.texture_option.set()==fruit_bowl[x][1]
            self.climate_option.set()==fruit_bowl[x][2]

root = Tk()
root.title("Fruit Bowl")
fruit = Fruit(root)
root.mainloop()

I am getting an error message, Name Error: global name ‘enter’ is not defined.
Does anyone know why this refuses to work?

  • 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-05-28T06:04:47+00:00Added an answer on May 28, 2026 at 6:04 am

    The problem is that you define the “enter” variable locally in one method of your object, and then tries to access it in another method – where it does not exist as a local variable (therefore Python searches it as a global variable, and as it does not find it, it raises the message error you saw).

    It is easy to fix: just set the enter variable to be an attribute of your “Fruit” class, by prefixing it with self. everywhere it is used – thus it will be available for all methods of your object –

    Namely, change this line:

    enter = Entry(self.search_frame, width=30).pack(side=LEFT, expand=NO, padx=5, pady=5, ipadx=5, ipady=5)

    to:

    self.enter = Entry(self.search_frame, width=30).pack(side=LEFT, expand=NO, padx=5, pady=5, ipadx=5, ipady=5)

    And

    if enter.get()==fruit_bowl[x][0]:
    to
    if self.enter.get()==fruit_bowl[x][0]:

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have some data like this: 1 2 3 4 5 9 2 6

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.