Reputation: 1
When I run the code, TK form should pop up But i am getting this error:
File "PycharmProjects/untitled/tkhello4.py", line 11, in resize
Label.config(font='Helvetica -%d bold' % scale.get())
TypeError: unbound method configure() must be called with Label instance as first argument (got nothing instead)
What could be wrong? Thank you overmuch.
Below is my code.
from Tkinter import *
def resize(ev=None):
Label.config(font='Helvetica -%d bold' % scale.get())
top = Tk()
top.geometry('250x150')
Lable = Label(top, text='Hello World!',
font='Helvetica -12 bold')
Lable.pack(fill=Y, expand=1)
scale= Scale(top, from_=10, to=40,
orient=HORIZONTAL, command=resize)
scale.set(12)
scale.pack(fill=X, expand=1)
quit = Button(top, text='QUIT', command=top.quit, activeforeground='white', activebackground='red')
quit.pack()
mainloop()
Upvotes: 0
Views: 548
Reputation: 15236
Change the name of your label to something that is not part of a built in function.
Keep this in mind when naming any variable. If you confuse the name space things can get messy. Always write variable names in a way that will avoid messing with the built in functions or any imported functions.
just rename your Label like the following. It is always best to follow PEP-8 style guide to prevent this kind of problem.
def resize(ev=None):
my_lable.config(font='Helvetica -%d bold' % scale.get())
my_lable = Label(top, text='Hello World!', font='Helvetica -12 bold')
my_lable.pack(fill=Y, expand=1)
Upvotes: 0
Reputation: 23216
You have a class Label
and a variable Lable
which seems a recipe for confusion ... which is exactly what has happened.
# here you refer to the class Label
Label.config(font='Helvetica -%d bold' % scale.get())
Should be
# but you should be using the instance Lable
Lable.config(font='Helvetica -%d bold' % scale.get())
Upvotes: 1