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 'odometer' not defined rfernandez15 1 105 Nov-25-2019, 09:57 PM
Last Post: ichabod801
  NameError: NameError: global name 'BPLInstruction' is not defined colt 7 364 Oct-27-2019, 07:49 AM
Last Post: Larz60+
  Function Annotation got NameError: name 'xxx' is not defined Lance 6 342 Oct-23-2019, 03:13 AM
Last Post: Lance
  NameError: name 'processing' is not defined soli004 2 464 Sep-07-2019, 11:57 AM
Last Post: soli004
  NameError: name 'display' is not defined when running code on power bi beginner1 2 1,811 Jul-24-2019, 11:03 AM
Last Post: beginner1
  [split] NameError: name 'lo' is not defined when using input ? Cedmo 2 447 Jul-05-2019, 09:39 PM
Last Post: Cedmo
  NameError: name 'lst' is not defined Jmekubo 2 851 Apr-27-2019, 12:34 PM
Last Post: Jmekubo
  *** NameError: name '' is not defined adamG 1 904 Apr-08-2019, 01:21 PM
Last Post: ichabod801
  help (variables) - NameError: name 'Payment' is not defined? Vqlk 5 591 Feb-27-2019, 04:57 PM
Last Post: buran
  NameError: name 'd' is not defined synthex 1 862 Feb-23-2019, 12:35 PM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)