Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 tkinter - "NameError: name 'frame' is not defined"
#1
I'm trying to create a class of buttons and bind it to tkinter but it keeps telling me "NameError: name 'frame' is not defined."

I tried this solution here but it's not working - https://stackoverflow.com/questions/4625...ned-python

Here's what it looks like:

>>> class AccountingButtons:

	def __init__(self, master):
		frame = Frame(master)
		frame.pack()

		
>>> self.incomeopButton = Button(frame, text="Display Income From Operations", command=self.income_from_operations)
Traceback (most recent call last):
  File "<pyshell#76>", line 1, in <module>
    self.incomeopButton = Button(frame, text="Display Income From Operations", command=self.income_from_operations)
NameError: name 'frame' is not defined
>>> from tkinter import Frame
>>> from tkinter import Text
>>> from tkinter import Label
>>> class AccountingButtons:

	def __init__(self, master):
		frame = Frame(master)
		frame.pack()

		
>>> self.incomeopButton = Button(frame, text="Display Income From Operations", command=self.income_from_operations)
Traceback (most recent call last):
  File "<pyshell#86>", line 1, in <module>
    self.incomeopButton = Button(frame, text="Display Income From Operations", command=self.income_from_operations)
NameError: name 'frame' is not defined
Yoriz wrote Jul-21-2019, 07:05 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#2
frame is not defined because
self.incomeopButton = Button(frame, text="Display Income From Operations", command=self.income_from_operations)
has not been added as part of the __init__ method of AccountingButtons, its in a separate command line.
create this code as a python file instead.
Quote
#3
(Jul-21-2019, 07:09 PM)Yoriz Wrote: frame is not defined because
self.incomeopButton = Button(frame, text="Display Income From Operations", command=self.income_from_operations)
has not been added as part of the __init__ method of AccountingButtons, its in a separate command line.
create this code as a python file instead.

Thank you for the help. I apologize for not posting properly and will do so in the future.

In the meantime though, can you link me to a description on how to do what you're describing? I want to make sure I don't make this errors or similar ones in the future.
Quote
#4
In the following link
https://python-forum.io/Thread-How-to-Ex...ython-code
you are currently using 1) Interactive Prompt, use 2) IDE (Python script)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  NameError: name 'pins' is not defined glennford49 2 441 Jun-15-2020, 12:20 PM
Last Post: glennford49
  python library not defined in user defined function johnEmScott 2 169 May-30-2020, 04:14 AM
Last Post: DT2000
  [split] NameError: name 'formats' is not defined shobhu123 1 341 May-24-2020, 06:29 PM
Last Post: Skaperen
  NameError: name 'cross_validation' is not defined tmhsa 5 930 Apr-21-2020, 08:15 PM
Last Post: DT2000
  NameError: name 'os' is not defined lrpirlet 6 1,153 Apr-01-2020, 08:43 PM
Last Post: buran
  NameError: name 'edit' is not defined CabbageMan 5 638 Dec-17-2019, 04:48 PM
Last Post: CabbageMan
  NameError 'odometer' not defined rfernandez15 1 433 Nov-25-2019, 09:57 PM
Last Post: ichabod801
  NameError: NameError: global name 'BPLInstruction' is not defined colt 7 761 Oct-27-2019, 07:49 AM
Last Post: Larz60+
  Function Annotation got NameError: name 'xxx' is not defined Lance 6 957 Oct-23-2019, 03:13 AM
Last Post: Lance
  NameError: name 'processing' is not defined soli004 2 1,087 Sep-07-2019, 11:57 AM
Last Post: soli004

Forum Jump:


Users browsing this thread: 1 Guest(s)