Python 3 tkinter Spinbox GUI Program Example

By | March 24, 2020

Topic: Python 3 tkinter Spinbox GUI Program Example

This Python GUI program using tkinter GUI package, shows the use of Spinbox widget. As the proggram is in execution state, its GUI main window will wait for user input. If the user will change the spinbox value by increasing or decreasing, the font size of label control’s text will also change accordingly.

The value in Spinbox widget is directly linked to font size. If the value in spinbox widget is 20, then fontsize of label widget will also be 20 and so on.

Python 3 tkinter Spinbox GUI Program Example

Python 3 tkinter Spinbox GUI Program Example

 

# Python 3 GUI program
# using Spinbox and Label
# widgets to increase font size
# of label by Spinbox change

from tkinter import*


def main():
    main_window = Tk()
    main_window.geometry("400x400")
    main_window.resizable(0, 0) 


    main_window.title('tkinter SpinBox Example')
    

    label1 = Label(main_window, text="Spin Box Example")

    label1.config(bg='green', fg='white', font=('verdana', 10))                  

        
    label1.place(x=30, y=50)

    def change_fontsize():
        font_size = int(spinbox1.get())
        label1.config(font=('verdana',font_size))
        
    label2 = Label(text="Increase / Decrease Font Size with Spinbox")
    label2.place(x=30,y=225)
    spinbox1 = Spinbox(main_window, from_=10, to=20,
                       command=change_fontsize,font=('verdana',15),width=5)
    spinbox1.place(x=130,y=250)

    label2 = Label(text="www.EasyCodeBook.com",
                   font=('verdana',15),fg='orange')
    label2.place(x=48,y=350)
    mainloop()

main()

Leave a Reply

Your email address will not be published. Required fields are marked *