Python Tutorial : Create a Counter

This tutorial will be how to create a counter using Python and the library tkinter

The tkinter library allows the user to create GUIs for users to interact with. Here tkinter will be used to create a frame the will contain a label, which will show the seconds being counted, and a stop button that will stop the counter and destroy the frame.

Start by creating the counting function. Here is a quick tutorial on Functions if you are unfamiliar with python functions.

seconds = 0
def seconds_Timer(Timer):
    seconds = 0
    # Counting function
    def count():
        global seconds
        seconds += 1
        Timer.config(text=str(seconds))
        Timer.after(1000, count)
    count()

Here is the frame the will contain the button and the seconds counted

# Creating the frame
root = tk.Tk()
# Setting Label
root.title("Counter")
Timer = tk.Label(root, fg="blue")
Timer.pack()
# Calling the Timer Function
seconds_Timer(Timer)
# Stop Button
button_STP = tk.Button(root, text='Stop', fg="red" , width=40, command=root.destroy)
# Adding the button 
button_STP.pack()

root.mainloop()
Output

Android Studio Loading Animation Between Activities

Progress Dialog is dialog showing a progress indicator and an optional text message or view. The methods of Progress Dialog being used in this tutorial are: ProgressDialog.setTitle() – Used to set title of dialog box ProgressDialog.setMessage() – Used to set dialog message being displayed ProgressDialog.setProgressStyle() – Choose the style of indicator ProgressDialog.dismiss() – Dismiss the … Read more Android Studio Loading Animation Between Activities

Android Studio Tutorial SeekBar

SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch thumb and drag left or right to set the current progress level or various other task. In this example, the seekbar will be used to display a percentage. As the user moves the SeekBar left to right the percentage value … Read more Android Studio Tutorial SeekBar

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s