-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2060 from NitkarshChourasia/testing
add: new gui based counter application.
- Loading branch information
Showing
4 changed files
with
175 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,13 @@ | ||
datetime | ||
subprocess | ||
pyjokes | ||
requests | ||
json | ||
Pillow | ||
Image | ||
Imagegrab | ||
gTTs | ||
ImageGrab | ||
gTTS | ||
keyboard | ||
Key | ||
Listener | ||
Button | ||
Controller | ||
key | ||
playsound | ||
pyttsx3 | ||
webbrowser | ||
smtplib | ||
speech_recognition | ||
openai | ||
SpeechRecognition | ||
openai |
69 changes: 69 additions & 0 deletions
69
nitkarshchourasia/GUI_apps/tkinter_apps/counter_app/counter_app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Author: Nitkarsh Chourasia | ||
# Date created: 28/12/2023 | ||
|
||
# Import the required libraries | ||
import tkinter as tk | ||
from tkinter import ttk | ||
|
||
|
||
class MyApplication: | ||
"""A class to create a counter app.""" | ||
|
||
def __init__(self, master): | ||
# Initialize the master window | ||
self.master = master | ||
# Set the title and geometry of the master window | ||
self.master.title("Counter App") | ||
self.master.geometry("300x300") | ||
|
||
# Create the widgets | ||
self.create_widgets() | ||
|
||
# Create the widgets | ||
def create_widgets(self): | ||
# Create a frame to hold the widgets | ||
frame = ttk.Frame(self.master) | ||
# Pack the frame to the master window | ||
frame.pack(padx=20, pady=20) | ||
|
||
# Create a label to display the counter | ||
self.label = ttk.Label(frame, text="0", font=("Arial Bold", 70)) | ||
# Grid the label to the frame | ||
self.label.grid(row=0, column=0, padx=20, pady=20) | ||
|
||
# Add a button for interaction to increase the counter | ||
add_button = ttk.Button(frame, text="Add", command=self.on_add_click) | ||
# Grid the button to the frame | ||
add_button.grid(row=1, column=0, pady=10) | ||
|
||
# Add a button for interaction to decrease the counter | ||
remove_button = ttk.Button(frame, text="Remove", command=self.on_remove_click) | ||
# Grid the button to the frame | ||
remove_button.grid(row=2, column=0, pady=10) | ||
|
||
# Add a click event handler | ||
def on_add_click(self): | ||
# Get the current text of the label | ||
current_text = self.label.cget("text") | ||
# Convert the text to an integer and add 1 | ||
new_text = int(current_text) + 1 | ||
# Set the new text to the label | ||
self.label.config(text=new_text) | ||
|
||
# Add a click event handler | ||
def on_remove_click(self): | ||
# Get the current text of the label | ||
current_text = self.label.cget("text") | ||
# Convert the text to an integer and subtract 1 | ||
new_text = int(current_text) - 1 | ||
# Set the new text to the label | ||
self.label.config(text=new_text) | ||
|
||
|
||
if __name__ == "__main__": | ||
# Create the root window | ||
root = tk.Tk() | ||
# Create an instance of the application | ||
app = MyApplication(root) | ||
# Run the app | ||
root.mainloop() |
50 changes: 50 additions & 0 deletions
50
...asia/GUI_apps/tkinter_apps/hello_world_excla_increment_app/hello_world_incre_decre_(!).py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import tkinter as tk | ||
from tkinter import ttk | ||
|
||
|
||
class MyApplication: | ||
def __init__(self, master): | ||
self.master = master | ||
# Want to understand why .master.title was used? | ||
self.master.title("Hello World") | ||
|
||
self.create_widgets() | ||
|
||
def create_widgets(self): | ||
frame = ttk.Frame(self.master) | ||
frame.pack(padx=20, pady=20) | ||
# grid and pack are different geometry managers. | ||
self.label = ttk.Label(frame, text="Hello World!", font=("Arial Bold", 50)) | ||
self.label.grid(row=0, column=0, padx=20, pady=20) | ||
|
||
# Add a button for interaction | ||
concat_button = ttk.Button( | ||
frame, text="Click Me!", command=self.on_button_click | ||
) | ||
concat_button.grid(row=1, column=0, pady=10) | ||
|
||
remove_button = ttk.Button( | ||
frame, text="Remove '!'", command=self.on_remove_click | ||
) | ||
remove_button.grid(row=2, column=0, pady=10) | ||
|
||
def on_button_click(self): | ||
current_text = self.label.cget("text") | ||
# current_text = self.label["text"] | ||
#! Solve this. | ||
new_text = current_text + "!" | ||
self.label.config(text=new_text) | ||
|
||
def on_remove_click(self): | ||
# current_text = self.label.cget("text") | ||
current_text = self.label["text"] | ||
#! Solve this. | ||
new_text = current_text[:-1] | ||
self.label.config(text=new_text) | ||
# TODO: Can make a char matching function, to remove the last char, if it is a '!'. | ||
|
||
|
||
if __name__ == "__main__": | ||
root = tk.Tk() | ||
app = MyApplication(root) | ||
root.mainloop() |
50 changes: 50 additions & 0 deletions
50
nitkarshchourasia/GUI_apps/tkinter_apps/hello_world_excla_increment_app/hello_world_label.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import tkinter as tk | ||
from tkinter import ttk | ||
|
||
|
||
class MyApplication: | ||
def __init__(self, master): | ||
self.master = master | ||
# Want to understand why .master.title was used? | ||
self.master.title("Hello World") | ||
|
||
self.create_widgets() | ||
|
||
def create_widgets(self): | ||
frame = ttk.Frame(self.master) | ||
frame.pack(padx=20, pady=20) | ||
# grid and pack are different geometry managers. | ||
self.label = ttk.Label(frame, text="Hello World!", font=("Arial Bold", 50)) | ||
self.label.grid(row=0, column=0, padx=20, pady=20) | ||
|
||
# Add a button for interaction | ||
concat_button = ttk.Button( | ||
frame, text="Click Me!", command=self.on_button_click | ||
) | ||
concat_button.grid(row=1, column=0, pady=10) | ||
|
||
remove_button = ttk.Button( | ||
frame, text="Remove '!'", command=self.on_remove_click | ||
) | ||
remove_button.grid(row=2, column=0, pady=10) | ||
|
||
def on_button_click(self): | ||
current_text = self.label.cget("text") | ||
# current_text = self.label["text"] | ||
#! Solve this. | ||
new_text = current_text + "!" | ||
self.label.config(text=new_text) | ||
|
||
def on_remove_click(self): | ||
# current_text = self.label.cget("text") | ||
current_text = self.label["text"] | ||
#! Solve this. | ||
new_text = current_text[:-1] | ||
self.label.config(text=new_text) | ||
# TODO: Can make a char matching function, to remove the last char, if it is a '!'. | ||
|
||
|
||
if __name__ == "__main__": | ||
root = tk.Tk() | ||
app = MyApplication(root) | ||
root.mainloop() |