Reputation: 21
Really simple code, but not working using tkinder in Python.
This code has been copied just as seen in a video tutorial, so I think it could be any config:
from tkinter import*
root=Tk()
miFrame=Frame(root, width=500, height=400)
miFrame=pack()
Label(miFrame, text="Hola alumnos de Python", fg="red", font=("Comic Sans
MS", 18)).place(x=100, y=200)
root.mainloop()
The error:
Traceback (most recent call last): File "Prueba2.py", line 7, in miFrame=pack() NameError: name 'pack' is not defined
Upvotes: 0
Views: 125
Reputation: 1
The row miFrame=pack()
is an attempt to assign a symbol miFrame
to a reference to some known function pack()
In a case, there is no such known to the python interpreter state, it threw an exception mentioned above.
However, the object miFrame
, being a row above that assigned to a tkinter.Frame
instance, there is an instance-method present - the .pack()
, that can be called, instead of an attempt to straight re-assign the miFrame
, right after it's instantiation:
miFrame = Frame( root, width = 500,
height = 400
)
miFrame.pack() #_____________________ .pack() is a Frame-class instance-method
Label( miFrame, text = "Hola alumnos de Python",
fg = "red",
font = ( "Comic Sans MS", 18 )
).place( x = 100,
y = 200
)
Upvotes: 0