From 46a26e2ef2d512d295d7c611500b622f9e875b6b Mon Sep 17 00:00:00 2001 From: Milind Thakur <46113414+milindthakur177@users.noreply.github.com> Date: Mon, 10 Feb 2020 21:49:05 +0530 Subject: [PATCH 1/2] adding focus on entry and adding a function It will focus on the entry so that one does not have to click on entry to enter value. The function will pronounce the weather. --- WeatherApp.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/WeatherApp.py b/WeatherApp.py index 467d3c9..fb73a67 100644 --- a/WeatherApp.py +++ b/WeatherApp.py @@ -1,6 +1,13 @@ import tkinter as tk import requests - +import pyttsx3 +engine= pyttsx3.init() +voices= engine.getProperty('voices') +engine.setProperty('voice',voices[1].id) +def say(word): + engine.say(word) + engine.runAndWait() + HEIGHT = 500 WIDTH = 600 @@ -30,6 +37,7 @@ def get_weather(city): weather = response.json() label['text'] = format_response(weather) + say(label['text']) @@ -47,6 +55,7 @@ def get_weather(city): entry = tk.Entry(frame, font=40) entry.place(relwidth=0.65, relheight=1) +entry.focus() button = tk.Button(frame, text="Get Weather", font=40, command=lambda: get_weather(entry.get())) button.place(relx=0.7, relheight=1, relwidth=0.3) @@ -57,4 +66,4 @@ def get_weather(city): label = tk.Label(lower_frame) label.place(relwidth=1, relheight=1) -root.mainloop() \ No newline at end of file +root.mainloop() From 4393bd55d6a879e5abf014c896afb73cec7bc764 Mon Sep 17 00:00:00 2001 From: Milind Thakur <46113414+milindthakur177@users.noreply.github.com> Date: Mon, 10 Feb 2020 21:52:26 +0530 Subject: [PATCH 2/2] adding focus to entry and adding a function It will focus on the entry when the app opens so that one does not have to click on entry to enter value. adding a function which will pronounce the weather before printing it. --- WeatherApp_withicons.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/WeatherApp_withicons.py b/WeatherApp_withicons.py index e21821a..64cf5ff 100644 --- a/WeatherApp_withicons.py +++ b/WeatherApp_withicons.py @@ -1,6 +1,14 @@ import tkinter as tk import requests from PIL import Image, ImageTk +import pyttsx3 +engine= pyttsx3.init() +voices= engine.getProperty('voices') +engine.setProperty('voice',voices[1].id) + +def say(word): + engine.say(word) + engine.runAndWait() app = tk.Tk() @@ -52,6 +60,7 @@ def open_image(icon): textbox = tk.Entry(frame, font=40) textbox.place(relwidth=0.65, relheight=1) +textbox.focus() submit = tk.Button(frame, text='Get Weather', font=40, command=lambda: get_weather(textbox.get())) #submit.config(font=) @@ -73,4 +82,4 @@ def open_image(icon): -app.mainloop() \ No newline at end of file +app.mainloop()