Returning a value from TkInter Slider + making slider horizontal with classes
Question: I am having a problem printing the value of a slider bar. I created a button
below the slider to do so, but it prints before it is pressed and doesn't
print when pressed.

I also have the problem of making teh slider horizontal. I know it is
"orient=HORIZONTAL" and it works when it is not in a class but when it is in a
class it gives me trouble.

Here is the code, and as always, thank you so much!! :)

    
    
    import Tkinter as tki # Tkinter -> tkinter in Python 3
    import tkMessageBox
    
    
    class GUI(tki.Tk):
            def __init__(self):
                    tki.Tk.__init__(self)
                    self.wm_title("Menu Title")
                    RWidth=500
                    RHeight=300
                    self.geometry(("%dx%d")%(RWidth,RHeight))
                    menubar = tki.Menu(self)
    
                    # create a pulldown menu, and add it to the menu bar
                    menu0 = tki.Menu(menubar, tearoff=0)
                    menu0.add_command(label="Run Slider", command=self.slider_prompt)
                    menu0.add_separator()
                    menu0.add_command(label="Exit", command=self.quit)
    
            menubar.add_cascade(label="Slider", menu=menu0)
    
                    # display the menu
                    self.config(menu=menubar)
    
            def slider_prompt(self, msg='This is a slider'):
                slider_window= self.top = tki.Toplevel(self)
                slider_window.title("Slider Title")
                RWidth=300
                RHeight=200
                slider_window.geometry(("%dx%d")%(RWidth,RHeight))
    
                label0 = tki.Label(slider_window, text=msg)
                label0.pack()
    
                slider = tki.Scale(slider_window, from_=100, to=1000) # have to make horizontal
                slider.pack()
    
                #put button here that starts the program (pass the slider value)
                button_cheat = tki.Button(   slider_window, text='Print Value', command=self.print_slide_value(slider.get())   )
                button_cheat.pack()
    
                button_close = tki.Button(slider_window, text='Exit', command=lambda: self.top.destroy())
                button_close.pack()
    
    
        def print_slide_value(self, slider_value):
            print slider_value
    
    gui = GUI()
    gui.mainloop()
    


Answer: When you use a command argument you have to pass there a reference to a
callable object. Function that will be called after the event. What you're
doing is that you're passing there the result from
`self.print_slide_value(slider.get())`, which is `None`.

Instead do:

    
    
    def print_slide_value():
        print slider.get()
    button_cheat = tki.Button(slider_window, text='Print Value', command=print_slide_value)
    

Also I had no problems with this:

    
    
    slider = tki.Scale(slider_window, from_=100, to=1000, orient=tki.HORIZONTAL)
    

