Skip to content

Commit 757e6a4

Browse files
committed
First commit
0 parents  commit 757e6a4

File tree

5 files changed

+292
-0
lines changed

5 files changed

+292
-0
lines changed

Calculator/icon.ico

105 KB
Binary file not shown.

Calculator/main.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
from tkinter import *
2+
3+
root = Tk()
4+
root.title("Calculator")
5+
root.configure(background = "black")
6+
root.iconbitmap('icon.ico')
7+
#root.geometry("340x555")
8+
root.minsize(340, 555)
9+
root.maxsize(340, 555)
10+
11+
12+
def click(event):
13+
global scvalue
14+
text = event.widget.cget("text")
15+
# print(text)
16+
if text == "=":
17+
if scvalue.get().isdigit():
18+
value = int(scvalue.get())
19+
else:
20+
value = eval(screen.get())
21+
scvalue.set(value)
22+
screen.update()
23+
24+
elif text == "Clear":
25+
scvalue.set("")
26+
screen.update()
27+
28+
else:
29+
scvalue.set(scvalue.get() + text)
30+
screen.update()
31+
32+
scvalue = StringVar()
33+
scvalue.set("")
34+
35+
screen = Entry(root, textvar = scvalue, font = "lucida 30 bold")
36+
screen.pack(fill = X, pady = 10, padx = 10)
37+
38+
39+
40+
f = Frame(root, bg = "black")
41+
42+
b = Button(f, text = "Clear", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=10)
43+
b.pack(side = LEFT, padx = 5, pady = 5)
44+
b.bind("<Button-1>", click)
45+
46+
b = Button(f, text = "%", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
47+
b.pack(side = LEFT, padx = 5, pady = 5)
48+
b.bind("<Button-1>", click)
49+
50+
f.pack()
51+
52+
53+
54+
f = Frame(root, bg = "black")
55+
56+
b = Button(f, text = "9", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
57+
b.pack(side = LEFT, padx = 5, pady = 5)
58+
b.bind("<Button-1>", click)
59+
60+
b = Button(f, text = "8", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
61+
b.pack(side = LEFT, padx = 5, pady = 5)
62+
b.bind("<Button-1>", click)
63+
64+
b = Button(f, text = "7", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
65+
b.pack(side = LEFT, padx = 5, pady = 5)
66+
b.bind("<Button-1>", click)
67+
68+
b = Button(f, text = "/", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
69+
b.pack(side = LEFT, padx = 5, pady = 5)
70+
b.bind("<Button-1>", click)
71+
72+
f.pack()
73+
74+
75+
76+
f = Frame(root, bg = "black")
77+
78+
b = Button(f, text = "6", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
79+
b.pack(side = LEFT, padx = 5, pady = 5)
80+
b.bind("<Button-1>", click)
81+
82+
b = Button(f, text = "5", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
83+
b.pack(side = LEFT, padx = 5, pady = 5)
84+
b.bind("<Button-1>", click)
85+
86+
b = Button(f, text = "4", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
87+
b.pack(side = LEFT, padx = 5, pady = 5)
88+
b.bind("<Button-1>", click)
89+
90+
b = Button(f, text = "*", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
91+
b.pack(side = LEFT, padx = 5, pady = 5)
92+
b.bind("<Button-1>", click)
93+
94+
f.pack()
95+
96+
97+
98+
f = Frame(root, bg = "black")
99+
100+
b = Button(f, text = "3", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
101+
b.pack(side = LEFT, padx = 5, pady = 5)
102+
b.bind("<Button-1>", click)
103+
104+
b = Button(f, text = "2", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
105+
b.pack(side = LEFT, padx = 5, pady = 5)
106+
b.bind("<Button-1>", click)
107+
108+
b = Button(f, text = "1", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
109+
b.pack(side = LEFT, padx = 5, pady = 5)
110+
b.bind("<Button-1>", click)
111+
112+
b = Button(f, text = "+", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
113+
b.pack(side = LEFT, padx = 5, pady = 5)
114+
b.bind("<Button-1>", click)
115+
116+
f.pack()
117+
118+
119+
120+
f = Frame(root, bg = "black")
121+
122+
b = Button(f, text = ".", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
123+
b.pack(side = LEFT, padx = 5, pady = 5)
124+
b.bind("<Button-1>", click)
125+
126+
b = Button(f, text = "0", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
127+
b.pack(side = LEFT, padx = 5, pady = 5)
128+
b.bind("<Button-1>", click)
129+
130+
b = Button(f, text = "=", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
131+
b.pack(side = LEFT, padx = 5, pady = 5)
132+
b.bind("<Button-1>", click)
133+
134+
b = Button(f, text = "-", bg="orange", padx = 10, pady = 10, font = "lucida 25 bold", width=2)
135+
b.pack(side = LEFT, padx = 5, pady = 5)
136+
b.bind("<Button-1>", click)
137+
138+
f.pack()
139+
140+
141+
root.mainloop()

Calculator/screenshot.png

8.68 KB
Loading

NewsBlog/NewsBlogSubscribers.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
('fari', '[email protected]', '9301249032')
2+
('reyan', '[email protected]', '1234567890')
3+
('alraaz', '[email protected]', '213124342`')

NewsBlog/main.py

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
from tkinter import *
2+
from PIL import Image, ImageTk
3+
import tkinter.messagebox as tmb
4+
import requests
5+
import urllib.parse
6+
import io
7+
8+
apiKey = ''
9+
url = 'https://newsapi.org/v2/top-headlines?country=in&category=technology&pageSize=10&apiKey=' + apiKey
10+
11+
r = requests.get(url).json()
12+
13+
# create instance
14+
window = Tk()
15+
# set default window size
16+
window.geometry('900x550')
17+
# set min window size
18+
window.minsize(700, 400)
19+
# set max window size
20+
window.maxsize(1100, 600)
21+
# add a title
22+
window.title("News Blog")
23+
24+
def subscribeUser():
25+
with open('NewsBlogSubscribers.txt', 'a') as f:
26+
f.write(f"{userName.get(), userEmail.get(), userPhone.get()}\n")
27+
28+
29+
def rateUs():
30+
a = tmb.askokcancel("Rate", "Would you like to rate us now?")
31+
if a==True:
32+
tmb.showinfo("Rated", "Thank you for taking your time to rate us.")
33+
else:
34+
tmb.showinfo("Not Rated", "We are looking forward to serve in much better way.\nThank You!")
35+
36+
def help():
37+
tmb.showinfo("Help","We are glad that you asked for help.\nWe will soon resolve your issue. Kindly wait for some time.\nThank You")
38+
39+
def error():
40+
tmb.showerror("Error", "This is an error message.")\
41+
42+
def submit():
43+
#tmb.showinfo("Slider", f"You've selected {myslider.get()} on slider.")
44+
tmb._show(title='Slider', message=f"You've selected {myslider.get()} on slider.", icon='info')
45+
46+
47+
def getFormattedText(text):
48+
count = 1
49+
formattedText = ''
50+
for ch in text:
51+
if(count%80 == 0):
52+
formattedText += '\n'
53+
formattedText += ch
54+
count += 1
55+
return formattedText
56+
57+
frames = []
58+
photos = []
59+
60+
def populate():
61+
#for i in range(len(r['articles'])):
62+
for i in range(2):
63+
frame = Frame(window, borderwidth=4, relief=RIDGE)
64+
frame.pack(fill=Y, pady=10, padx=10)
65+
66+
print(r['articles'][i]['urlToImage'])
67+
raw_data = urllib.request.urlopen(r['articles'][i]['urlToImage']).read()
68+
image = Image.open(io.BytesIO(raw_data))
69+
image = image.resize((100, 100), Image.ANTIALIAS)
70+
photo = ImageTk.PhotoImage(image)
71+
photos.append(photo)
72+
73+
image_label = Label(
74+
master=frame,
75+
image=photo,
76+
)
77+
image_label.pack(side=LEFT, padx=2, pady=2)
78+
79+
text_frame = Frame(frame)
80+
text_frame.pack(side=RIGHT)
81+
82+
title = Label(text_frame, fg='red',
83+
text = getFormattedText(r['articles'][i]['title']),
84+
font=("comicsans", 12, "bold"),
85+
)
86+
title.pack(padx=5, pady=5)
87+
88+
desc = Label(text_frame, text = getFormattedText(r['articles'][i]['description']))
89+
#desc = Label(text_frame, text = r['articles'][i]['content'])
90+
desc.pack(pady=10)
91+
92+
date = Label(text_frame, text=r['articles'][i]['publishedAt'])
93+
date.pack(side=RIGHT, padx=2)
94+
95+
frames.append(frame)
96+
frames[i].pack()
97+
98+
99+
# --------------------- Menu Bar ---------------------
100+
myMenuBar = Menu(window)
101+
102+
m1 = Menu(myMenuBar, tearoff=0)
103+
m1.add_command(label='Rate Us', command=rateUs)
104+
m1.add_command(label='Help', command=help)
105+
m1.add_command(label='Error', command=error)
106+
107+
myMenuBar.add_cascade(label='Options', menu=m1)
108+
myMenuBar.add_command(label='Exit', command=quit)
109+
window.config(menu=myMenuBar)
110+
111+
112+
# --------------------- Slider with Button ---------------------
113+
slider_frame = Frame(window)
114+
slider_frame.pack()
115+
#Creating Slider/Scroll Bar
116+
myslider = Scale(slider_frame, from_ = 0, to = 10, tickinterval=2, orient = HORIZONTAL)
117+
myslider.pack(side=LEFT)
118+
119+
#To change the By-Default Value from 0 to 10
120+
myslider.set(1)
121+
Button(slider_frame, text='Submit', command=submit).pack(side=RIGHT)
122+
123+
124+
# --------------------- Add news item to the window ---------------------
125+
populate()
126+
127+
128+
# --------------------- Subscription Form ---------------------
129+
Label(window, text='Subscribe to our blog', font=("comicsans", 15, "bold")).pack()
130+
131+
form_frame = Frame(window)
132+
form_frame.pack(side=LEFT)
133+
134+
userName = StringVar()
135+
userEmail = StringVar()
136+
userPhone = StringVar()
137+
138+
Label(form_frame, text='Name: ', padx=3, pady=3).grid(row=1, column=1)
139+
Label(form_frame, text='Email: ', padx=3, pady=3).grid(row=2, column=1)
140+
Label(form_frame, text='Phone: ', padx=3, pady=3).grid(row=3, column=1)
141+
142+
Entry(form_frame, textvariable=userName).grid(row=1, column=2)
143+
Entry(form_frame, textvariable=userEmail).grid(row=2, column=2)
144+
Entry(form_frame, textvariable=userPhone).grid(row=3, column=2)
145+
146+
Button(form_frame, text='Subscribe', command=subscribeUser).grid(row=4, column=1, padx=10, pady=10)
147+
148+
window.mainloop()

0 commit comments

Comments
 (0)