Python Forum
tkinter - "NameError: name 'frame' is not defined"
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
Reply
#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.
Reply
#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.
Reply
#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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I'm getting a NameError: ...not defined. vonArre 2 155 Mar-24-2024, 10:25 PM
Last Post: vonArre
  Getting NameError for a function that is defined JonWayn 2 1,056 Dec-11-2022, 01:53 PM
Last Post: JonWayn
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 2,774 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  [split] NameError: name 'csvwriter' is not defined. Did you mean: 'writer'? cathy12 4 3,200 Sep-01-2022, 07:41 PM
Last Post: deanhystad
  NameError: name ‘app_ctrl’ is not defined 3lnyn0 0 1,457 Jul-04-2022, 08:08 PM
Last Post: 3lnyn0
  NameError: name 'hash_value_x_t' is not defined Anldra12 5 1,864 May-13-2022, 03:37 PM
Last Post: deanhystad
  NameError: name 'cross_validation' is not defined tmhsa 6 13,182 Jan-17-2022, 09:53 PM
Last Post: TropicalHeat
  NameError: name “x” is not defined ... even though x is defined campjaybellson 7 14,673 Oct-20-2021, 05:39 PM
Last Post: deanhystad
  NameError: name 'Particle' is not defined in Pygame drunkenneo 4 3,299 Aug-15-2021, 06:12 PM
Last Post: bowlofred
  NameError: name 'u1' is not defined (on parser code Python) Melcu54 1 2,844 Jul-26-2021, 04:36 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020