Skip to content

Commit c695fea

Browse files
update: Update with documentation.
Update the counter app with comments and documentation.
1 parent 461597e commit c695fea

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed
Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,69 @@
1+
# Author: Nitkarsh Chourasia
2+
# Date created: 28/12/2023
3+
4+
# Import the required libraries
15
import tkinter as tk
26
from tkinter import ttk
37

4-
# Creating a counter app using tkinter
5-
68

79
class MyApplication:
10+
"""A class to create a counter app."""
11+
812
def __init__(self, master):
13+
# Initialize the master window
914
self.master = master
15+
# Set the title and geometry of the master window
1016
self.master.title("Counter App")
1117
self.master.geometry("300x300")
1218

19+
# Create the widgets
1320
self.create_widgets()
1421

22+
# Create the widgets
1523
def create_widgets(self):
24+
# Create a frame to hold the widgets
1625
frame = ttk.Frame(self.master)
26+
# Pack the frame to the master window
1727
frame.pack(padx=20, pady=20)
1828

29+
# Create a label to display the counter
1930
self.label = ttk.Label(frame, text="0", font=("Arial Bold", 70))
31+
# Grid the label to the frame
2032
self.label.grid(row=0, column=0, padx=20, pady=20)
2133

34+
# Add a button for interaction to increase the counter
2235
add_button = ttk.Button(frame, text="Add", command=self.on_add_click)
36+
# Grid the button to the frame
2337
add_button.grid(row=1, column=0, pady=10)
2438

39+
# Add a button for interaction to decrease the counter
2540
remove_button = ttk.Button(frame, text="Remove", command=self.on_remove_click)
41+
# Grid the button to the frame
2642
remove_button.grid(row=2, column=0, pady=10)
2743

44+
# Add a click event handler
2845
def on_add_click(self):
46+
# Get the current text of the label
2947
current_text = self.label.cget("text")
48+
# Convert the text to an integer and add 1
3049
new_text = int(current_text) + 1
50+
# Set the new text to the label
3151
self.label.config(text=new_text)
3252

53+
# Add a click event handler
3354
def on_remove_click(self):
55+
# Get the current text of the label
3456
current_text = self.label.cget("text")
57+
# Convert the text to an integer and subtract 1
3558
new_text = int(current_text) - 1
59+
# Set the new text to the label
3660
self.label.config(text=new_text)
3761

3862

3963
if __name__ == "__main__":
64+
# Create the root window
4065
root = tk.Tk()
66+
# Create an instance of the application
4167
app = MyApplication(root)
68+
# Run the app
4269
root.mainloop()

0 commit comments

Comments
 (0)