4

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.

finefoot
  • 9,914
  • 7
  • 59
  • 102
user2666750
  • 582
  • 1
  • 7
  • 11
  • 4
    @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. – PM 2Ring Oct 27 '14 at 07:35
  • @PM2Ring: suspected as much, that's why I didn't post an answer :-) (I don't actually know python.) Thanks for the info. – Mat Oct 27 '14 at 08:35
  • @Mat: No worries. I guess you're coming from Tcl/Tk, or some other version of Tk? – PM 2Ring Oct 28 '14 at 11:28

1 Answers1

7

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

Nilesh
  • 20,521
  • 16
  • 92
  • 148