Tkinter Scale and Spinbox in Python

Hello friends how are you, today in this blog i will teach you what is Scale and Spinbox, syntax of Scale and Spinbox, how to create Scale and Spinbox, how Scale and Spinbox work in a very simple way.

Let's start 

TKinter Scale

  • It is used to provide the graphical slider.
  • It allows us to select value from the slider
  • Syntax:
    s = Scale ( master, option1,option2, ... )
    
  • Here master is parent window and option can be used as a key-value pairs.
  • Examples of options are bg,font,width,height etc.

from tkinter import *
top = Tk()
top.geometry("200x150")
top['bg']="#51E1DC"
#define function
def myFun():
    sel = "Selected Value = " + str(var.get())
    label.config(text=sel)
var = IntVar()
#create scale
Scale(top, variable=var, from_=10, to=20, orient=HORIZONTAL).pack(anchor=CENTER,pady=5)
#create button
Button(top, text="Value", command=myFun).pack()
label = Label(top)
label.pack()
top.mainloop()
 



 Spinbox

  • It is approaximately same as tkinter Entry but in Spinbox we can provide range of values to the user ,out of which ,user can select one.
  • Syntax:
    m = Spinbox ( master, option1,option2, ... )
    
  • Here master is parent window and option can be used as a key-value pairs.
  • Examples of options are bg,font,width,height etc.

from tkinter import *
top = Tk()
top['bg']="#51E1DC"
top.geometry("200x150")
#create spinbox
Spinbox(top, from_=10, to=20).pack(pady=5)
top.mainloop()
 



Here in the above output screenshot you can increase and decrease the data in textbox by clicking on upside and downside arrow buttons.

Request:-If you found this post helpful then let me know by your comment and share it with your friend. 

If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all. 

If you have not subscribed my website then please subscribe my website. Try to learn something new and teach something new to other. 

Thanks.😊

Post a Comment

0 Comments