-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
74 lines (62 loc) · 2.48 KB
/
start.py
File metadata and controls
74 lines (62 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import tkinter as tk
from tkinter import filedialog, messagebox
# Import modules
try:
from scraper import scrape
except ImportError:
def scrape(url):
raise ImportError("The scraper module is missing or has errors.")
try:
from get_coordinates import get_coordinates
except ImportError:
def get_coordinates(location):
raise ImportError("The get_coordinates module is missing or has errors.")
# try:
# from is_weather_good_here import is_weather_good_here
# except ImportError:
# def is_weather_good_here(location):
# raise ImportError("The get_coordinates module is missing or has errors.")
def scrape_website():
url = website_url_entry.get()
if not url:
messagebox.showerror("Error", "Please enter a website URL.")
return
try:
result = scrape(url)
messagebox.showinfo("Success", f"Website scraped successfully!\n\n{result[:500]}...")
except Exception as e:
messagebox.showerror("Error", f"An error occurred: {e}")
def get_location_coordinates():
location = location_entry.get()
if not location:
messagebox.showerror("Error", "Please enter a location.")
return
try:
coordinates = get_coordinates(location)
messagebox.showinfo("Success", f"Coordinates:\n {coordinates["lat"]}, {coordinates["lng"]}")
except Exception as e:
messagebox.showerror("Error", f"An error occurred: {e}")
# Create the main window
root = tk.Tk()
root.title("Python Script GUI")
# Menu Bar
menu = tk.Menu(root)
root.config(menu=menu)
file_menu = tk.Menu(menu, tearoff=0)
menu.add_cascade(label="File", menu=file_menu)
file_menu.add_command(label="Exit", command=root.quit)
# Web Scraper Section
tk.Label(root, text="Web Scraper").grid(row=2, column=0, pady=10, padx=10, sticky="w")
website_url_entry = tk.Entry(root, width=50)
website_url_entry.grid(row=3, column=0, padx=10, pady=5)
tk.Button(root, text="Scrape Website", command=scrape_website).grid(row=3, column=1, padx=10, pady=5)
# Get Coordinates Section
tk.Label(root, text="Get Location Coordinates").grid(row=4, column=0, pady=10, padx=10, sticky="w")
location_entry = tk.Entry(root, width=50)
location_entry.grid(row=5, column=0, padx=10, pady=5)
tk.Button(root, text="Get Coordinates", command=get_location_coordinates).grid(row=5, column=1, padx=10, pady=5)
# Status Bar
status = tk.Label(root, text="Ready", bd=1, relief=tk.SUNKEN, anchor="w")
status.grid(row=6, column=0, columnspan=2, sticky="we")
# Run the GUI
root.mainloop()