Skip to content

Commit 125ee29

Browse files
Merge pull request #2060 from NitkarshChourasia/testing
add: new gui based counter application.
2 parents 08f67c8 + c6bec93 commit 125ee29

File tree

4 files changed

+175
-12
lines changed

4 files changed

+175
-12
lines changed

JARVIS/requirements.txt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
datetime
2-
subprocess
32
pyjokes
43
requests
5-
json
4+
Pillow
65
Image
7-
Imagegrab
8-
gTTs
6+
ImageGrab
7+
gTTS
98
keyboard
10-
Key
11-
Listener
12-
Button
13-
Controller
9+
key
1410
playsound
1511
pyttsx3
16-
webbrowser
17-
smtplib
18-
speech_recognition
19-
openai
12+
SpeechRecognition
13+
openai
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Author: Nitkarsh Chourasia
2+
# Date created: 28/12/2023
3+
4+
# Import the required libraries
5+
import tkinter as tk
6+
from tkinter import ttk
7+
8+
9+
class MyApplication:
10+
"""A class to create a counter app."""
11+
12+
def __init__(self, master):
13+
# Initialize the master window
14+
self.master = master
15+
# Set the title and geometry of the master window
16+
self.master.title("Counter App")
17+
self.master.geometry("300x300")
18+
19+
# Create the widgets
20+
self.create_widgets()
21+
22+
# Create the widgets
23+
def create_widgets(self):
24+
# Create a frame to hold the widgets
25+
frame = ttk.Frame(self.master)
26+
# Pack the frame to the master window
27+
frame.pack(padx=20, pady=20)
28+
29+
# Create a label to display the counter
30+
self.label = ttk.Label(frame, text="0", font=("Arial Bold", 70))
31+
# Grid the label to the frame
32+
self.label.grid(row=0, column=0, padx=20, pady=20)
33+
34+
# Add a button for interaction to increase the counter
35+
add_button = ttk.Button(frame, text="Add", command=self.on_add_click)
36+
# Grid the button to the frame
37+
add_button.grid(row=1, column=0, pady=10)
38+
39+
# Add a button for interaction to decrease the counter
40+
remove_button = ttk.Button(frame, text="Remove", command=self.on_remove_click)
41+
# Grid the button to the frame
42+
remove_button.grid(row=2, column=0, pady=10)
43+
44+
# Add a click event handler
45+
def on_add_click(self):
46+
# Get the current text of the label
47+
current_text = self.label.cget("text")
48+
# Convert the text to an integer and add 1
49+
new_text = int(current_text) + 1
50+
# Set the new text to the label
51+
self.label.config(text=new_text)
52+
53+
# Add a click event handler
54+
def on_remove_click(self):
55+
# Get the current text of the label
56+
current_text = self.label.cget("text")
57+
# Convert the text to an integer and subtract 1
58+
new_text = int(current_text) - 1
59+
# Set the new text to the label
60+
self.label.config(text=new_text)
61+
62+
63+
if __name__ == "__main__":
64+
# Create the root window
65+
root = tk.Tk()
66+
# Create an instance of the application
67+
app = MyApplication(root)
68+
# Run the app
69+
root.mainloop()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import tkinter as tk
2+
from tkinter import ttk
3+
4+
5+
class MyApplication:
6+
def __init__(self, master):
7+
self.master = master
8+
# Want to understand why .master.title was used?
9+
self.master.title("Hello World")
10+
11+
self.create_widgets()
12+
13+
def create_widgets(self):
14+
frame = ttk.Frame(self.master)
15+
frame.pack(padx=20, pady=20)
16+
# grid and pack are different geometry managers.
17+
self.label = ttk.Label(frame, text="Hello World!", font=("Arial Bold", 50))
18+
self.label.grid(row=0, column=0, padx=20, pady=20)
19+
20+
# Add a button for interaction
21+
concat_button = ttk.Button(
22+
frame, text="Click Me!", command=self.on_button_click
23+
)
24+
concat_button.grid(row=1, column=0, pady=10)
25+
26+
remove_button = ttk.Button(
27+
frame, text="Remove '!'", command=self.on_remove_click
28+
)
29+
remove_button.grid(row=2, column=0, pady=10)
30+
31+
def on_button_click(self):
32+
current_text = self.label.cget("text")
33+
# current_text = self.label["text"]
34+
#! Solve this.
35+
new_text = current_text + "!"
36+
self.label.config(text=new_text)
37+
38+
def on_remove_click(self):
39+
# current_text = self.label.cget("text")
40+
current_text = self.label["text"]
41+
#! Solve this.
42+
new_text = current_text[:-1]
43+
self.label.config(text=new_text)
44+
# TODO: Can make a char matching function, to remove the last char, if it is a '!'.
45+
46+
47+
if __name__ == "__main__":
48+
root = tk.Tk()
49+
app = MyApplication(root)
50+
root.mainloop()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import tkinter as tk
2+
from tkinter import ttk
3+
4+
5+
class MyApplication:
6+
def __init__(self, master):
7+
self.master = master
8+
# Want to understand why .master.title was used?
9+
self.master.title("Hello World")
10+
11+
self.create_widgets()
12+
13+
def create_widgets(self):
14+
frame = ttk.Frame(self.master)
15+
frame.pack(padx=20, pady=20)
16+
# grid and pack are different geometry managers.
17+
self.label = ttk.Label(frame, text="Hello World!", font=("Arial Bold", 50))
18+
self.label.grid(row=0, column=0, padx=20, pady=20)
19+
20+
# Add a button for interaction
21+
concat_button = ttk.Button(
22+
frame, text="Click Me!", command=self.on_button_click
23+
)
24+
concat_button.grid(row=1, column=0, pady=10)
25+
26+
remove_button = ttk.Button(
27+
frame, text="Remove '!'", command=self.on_remove_click
28+
)
29+
remove_button.grid(row=2, column=0, pady=10)
30+
31+
def on_button_click(self):
32+
current_text = self.label.cget("text")
33+
# current_text = self.label["text"]
34+
#! Solve this.
35+
new_text = current_text + "!"
36+
self.label.config(text=new_text)
37+
38+
def on_remove_click(self):
39+
# current_text = self.label.cget("text")
40+
current_text = self.label["text"]
41+
#! Solve this.
42+
new_text = current_text[:-1]
43+
self.label.config(text=new_text)
44+
# TODO: Can make a char matching function, to remove the last char, if it is a '!'.
45+
46+
47+
if __name__ == "__main__":
48+
root = tk.Tk()
49+
app = MyApplication(root)
50+
root.mainloop()

0 commit comments

Comments
 (0)