-1

This is my code and the scale bar does not display. Any suggestion?

from tkinter import *

self.mAsk = Scale(root, orient="horizontal", from_=1, to=16, label = "Mines", resolution = 1, sliderlength=25)
root=Tk()
root.mainloop()
finefoot
  • 9,914
  • 7
  • 59
  • 102
Jofbr
  • 455
  • 3
  • 23

1 Answers1

1

You have at least three problems here:

  • You try to use the global root before defining it, so your program is just going to raise a NameError.
  • You're assigning something to self.mAsk when you don't have anything named self, so that's also going to raise a NameError. (Do you not understand what classes are, and why self appears in methods of classes in many tkinter examples?)
  • You're not calling pack, grid, or place to actually place mAsk on the parent window. See the chapters on the three different Geometry Managers in the Tkinter book if you have no idea what this means.

If you fix all three, then it works:

from tkinter import *

root=Tk()
mAsk = Scale(root, orient="horizontal", from_=1, to=16, label = "Mines", resolution = 1, sliderlength=25)
mAsk.pack()
root.mainloop()
abarnert
  • 354,177
  • 51
  • 601
  • 671