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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:50:35+00:00 2026-06-03T08:50:35+00:00

What am I doing wrong? I want the ‘refreshB’ button to call the ‘update’

  • 0

What am I doing wrong? I want the ‘refreshB’ button to call the ‘update’ def but I get a nameError instead

class monitor():
    def update(self):
        print "Called"

    mon = Tk()
    mainFrame = Frame(mon)
    mainFrame.grid(row=1, column=1)

    optionFrame = Frame(mainFrame)
    optionFrame.grid(row=1, column=1)

    refreshB = ttk.Button(optionFrame, text='Refresh', command=lambda: update('self') )
    refreshB.grid(row=1, column=1)

    mon.mainloop()

monitor()


**NameError: global name 'update' is not defined**

I an not very familiar with Classes, is there something else I am supposed to add?

If the script above was not a class then I would use:

refreshB = ttk.Button(optionFrame, text='Refresh', command=lambda: update )

Which would works fine…

  • 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-03T08:50:37+00:00Added an answer on June 3, 2026 at 8:50 am

    Place all your initialization code inside an initialization function. Then refer to update() as self.update().

        class Monitor(object):
            def update(self, event):
                print "Called"
    
            def __init__(self):
                self.mon = Tk()
                self.mainFrame = Frame(self.mon)
                self.mainFrame.grid(row=1, column=1)
    
                self.optionFrame = Frame(self.mainFrame)
                self.optionFrame.grid(row=1, column=1)
    
                self.refreshB = ttk.Button(self.optionFrame, text='Refresh', command=self.update)
                self.refreshB.grid(row=1, column=1)
    
            def run(self):
                self.mon.mainloop()
    
        monitor = Monitor()
        monitor.run()
    

    the update() reference doesn’t work here because it’s an instancemethod and not a classmethod. Not because of the use of lambda–although I have no idea why you’d need to use a lambda function anyways. My solution involves you creating an instance of Monitor. This is useful because it allows you to control when the code within Monitor is executed. (Otherwise the code in your class body is executed at definition time. All calling monitor() does is return an instance of the class monitor–it doesn’t execute the body of the code)

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

Sidebar

Related Questions

Total newbie question, but I cant figure out what im doing wrong. I want
I am not certain what I am doing wrong, but I have a class
I'm not sure what I'm doing wrong here but I want to create scope
Where am i doing wrong? This is the normal print preview: But I want
Perhaps I'm doing this wrong. I want to set up a base class and
so I don't understand what I am doing wrong here. I want to populate
Ran into something interesting, want to know if I'm doing something wrong or if
What am I doing wrong here? I'm trying to get started with jQuery UI
What am I doing wrong here: class Helo { // main: generate some simple
What am I doing wrong that an exception is thrown instead of showing a

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.