Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """Spinbox, self contained example v1.3
- By Steve Shambles. Upadted Nov 2019
- Plenty more outrageous code atrocities at:
- stevepython.wordpress.com
- """
- from tkinter import Button, IntVar, LabelFrame
- from tkinter import messagebox, N, RIDGE, Spinbox, TclError, Tk, W
- root = Tk()
- root.title('Spinbox V1.2')
- root.geometry('180x90')
- root.resizable(False, False)
- def spn_bx_val():
- """Get value from the spinbox. Show value in a pop up."""
- # If input is invalid, eg.non-numeric, then return
- try:
- spv = VAR.get()
- except TclError:
- return
- messagebox.showinfo('Spinbox', 'Spinbox value is currently '+str(spv))
- # Create labelframe for the spinbox.
- spinbox_frame = LabelFrame(root, relief=RIDGE,
- fg='blue', text='Spinbox')
- spinbox_frame.grid(sticky=N, padx=10, pady=13)
- # Create the spinbox.
- VAR = IntVar()
- VAR.set(50) # Default start value.
- SPIN = Spinbox(spinbox_frame, from_=0, to=100, width=4, textvariable=VAR)
- # Create the 'spinbox value' button.
- Button(spinbox_frame, bg='green2', text='Spinbox value',
- command=spn_bx_val).grid(row=0, column=1, sticky=W)
- SPIN.grid(column=0, row=0, padx=10, pady=10)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement