Setting `orient` keyword argument for Tkinter Scale widget results in NameError: name 'HORIZONTAL' is not defined
Asked Answered
M

1

6

Here is my code:

import Tkinter

top = Tkinter.Tk()
top.geometry('600x600')

scale = Tkinter.Scale(top,from_=10,to=40, orient=HORIZONTAL)
scale.pack()

The following error appeared:

NameError: name 'HORIZONTAL' is not defined

I want to set my scale to be horizontal, and my reference is here but it doesn't work.

Maitland answered 27/10, 2014 at 6:44 Comment(3)
@Mat and user2666750 : import * can be handy when you're experimenting, but it's a bad habit to get into. Tkinter.HORIZONTAL is much better as it doesn't clutter your namespace with all the Tkinter stuff. If you do import * with multiple modules, things get very messy if the same name is used in more than one module. :) As a compromise, you can give a module a shorter name using import ... as ... syntax.Triiodomethane
@PM2Ring: suspected as much, that's why I didn't post an answer :-) (I don't actually know python.) Thanks for the info.Iphigenia
@Mat: No worries. I guess you're coming from Tcl/Tk, or some other version of Tk?Triiodomethane
G
9

HORIZONTAL is Tkinter's variable. If you want to use it you have to import it or have to use like Tkinter.HORIZONTAL

If you dont want to add Tkinter then you can do from Tkinter import HORIZONTAL

Germanize answered 27/10, 2014 at 6:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.