-2

i have a class here and using some functions, i have an other function, i want to execute that when one of the other does his job:

class Bio:
    ...

   def re_enter():
        print('hi')

   def enter(self):
        ''' User has done all steps and continue'''
        button = tkinter.Button(self.frame,text='Enter',command= re_enter)
        button.grid(row=3,column=0,sticky='news', padx=20,pady=10)

but i get a NameError, says re_enter is not defined.

Payam
  • 57
  • 7

1 Answers1

0

Because in the class you are using self in the caller definition and not in the second function to fix this, update following two things in your code

  1. update definition of re_enter() to re_enter(self)
  2. call re_enter as self.re_enter

Check the updated code as following

class Bio:
    ...

   def re_enter(self):
        print('hi')

   def enter(self):
        ''' User has done all steps and continue'''
        button = tkinter.Button(self.frame,text='Enter',command=self.re_enter)
        button.grid(row=3,column=0,sticky='news', padx=20,pady=10)
Zain Ul Abidin
  • 2,467
  • 1
  • 17
  • 29