Untitled
Anonymous
Plain Text
09/18/2025 10:05 AM
1.1 KB
16
Indexable
Never
import tkinter as tk
# Create the main window
root = tk.Tk()
root.title("Spinner")
root.geometry("250x150")
# Variable to keep track of the number
current_number = 0
# Functions to handle the button clicks
def count_up():
global current_number
current_number += 1
number_label.config(text=str(current_number))
def count_down():
global current_number
current_number -= 1
number_label.config(text=str(current_number))
def reset_number():
global current_number
current_number = 0
number_label.config(text=str(current_number))
# Create and place the widgets
number_label = tk.Label(root, text=str(current_number), font=("Arial", 24))
number_label.grid(row=0, column=0, rowspan=3, padx=20, pady=20)
count_up_button = tk.Button(root, text="+", command=count_up)
count_up_button.grid(row=0, column=1, pady=5)
count_down_button = tk.Button(root, text="-", command=count_down)
count_down_button.grid(row=1, column=1, pady=5)
reset_button = tk.Button(root, text="Reset", command=reset_number)
reset_button.grid(row=2, column=1, pady=5)
# Start the application
root.mainloop()Editor is loading...
Leave a Comment