CITY TEMERATURE CHECKER
Source Code:-
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | # GUI TEMPERATURE CHECKER from tkinter import * import requests from bs4 import BeautifulSoup root = Tk() root.geometry( "870x400+100+50" ) root.title( "City Temperature Checker" ) root.config(bg = "lightgreen" ) # Function Define for Calculating the Temperature def temp(): search = City.get() r = requests.get(url) s = BeautifulSoup(r.text, "html.parser" ) weather = s.find( "div" , class_ = "BNeawe" ).text Temp. set (weather) # Create a Function to Clear All Entry def clear(): City. set ("") Temp. set ( "0°C" ) # Display a Label Label(root, text = "Weather Temperature Checker " , font = ( "None 35 bold underline" ), bg = "lightgreen" ).place(x = 120 , y = 5 ) # Display a Label and create a Entry Label(root, text = "Enter a City Name:" , font = ( "None 30 bold" ), bg = "lightgreen" , fg = "green" ).place(x = 70 , y = 100 ) City = StringVar() Entry(root, textvariable = City, font = ( "None 25 bold" ), width = 15 , bg = "khaki1" ).place(x = 470 , y = 105 ) # Display a Label and create a Entry to Display Temperature Label(root, text = "Current Temperature in your City is:" , font = ( "None 30 bold" ), bg = "lightgreen" , fg = "blue4" ).place(x = 30 , y = 180 ) Temp = StringVar() Temp. set ( "0°C" ) Entry(root, textvariable = Temp, font = ( "None 25 bold" ), width = 5 , bg = "khaki1" ).place(x = 730 , y = 185 ) # Create a Buttton Button(root, text = "Check Temperature" , command = temp, font = ( "None 25 bold" ), bg = "yellow" , activebackground = "green1" ).place(x = 150 , y = 280 ) Button(root, text = "Clear" , command = clear, font = ( "None 25 bold" ), bg = "coral" , activebackground = "coral3" ).place(x = 580 , y = 280 ) root.mainloop() |
# GUI TEMPERATURE CHECKER from tkinter import * import requests from bs4 import BeautifulSoup root = Tk() root.geometry("870x400+100+50") root.title("City Temperature Checker") root.config(bg="lightgreen") # Function Define for Calculating the Temperature def temp(): search = City.get() url = f"https://www.google.com/search?&q=weather+in+{search}" r = requests.get(url) s = BeautifulSoup(r.text, "html.parser") weather = s.find("div", class_="BNeawe").text Temp.set(weather) # Create a Function to Clear All Entry def clear(): City.set("") Temp.set("0°C") # Display a Label Label(root, text="Weather Temperature Checker ", font=("None 35 bold underline"), bg="lightgreen").place(x=120, y=5) # Display a Label and create a Entry Label(root, text="Enter a City Name:", font=("None 30 bold"), bg="lightgreen", fg="green").place(x=70, y=100) City = StringVar() Entry(root, textvariable=City, font=("None 25 bold"), width=15, bg="khaki1").place(x=470, y=105) # Display a Label and create a Entry to Display Temperature Label(root, text="Current Temperature in your City is:", font=("None 30 bold"), bg="lightgreen", fg="blue4").place(x=30, y=180) Temp = StringVar() Temp.set("0°C") Entry(root, textvariable=Temp, font=("None 25 bold"), width=5, bg="khaki1").place(x=730, y=185) # Create a Buttton Button(root, text="Check Temperature", command=temp, font=("None 25 bold"), bg="yellow", activebackground="green1").place(x=150, y=280) Button(root, text="Clear", command=clear, font=("None 25 bold"), bg="coral", activebackground="coral3").place(x=580, y=280) root.mainloop()
Follow me on Instagram:- Python_with_Shubham
0 Comments