-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Couldn't load before the results came in so effectively useless.
- Loading branch information
Showing
2 changed files
with
69 additions
and
85 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
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,29 +1,80 @@ | ||
import tkinter as tk | ||
from __future__ import annotations | ||
|
||
from platform import system | ||
from tkinter import Event, Menu, Tk, Toplevel, messagebox | ||
from tkinter.ttk import Button, Entry, Frame, Label, Progressbar, Style | ||
|
||
class SampleApp(tk.Tk): | ||
from pyowm import OWM | ||
from pyowm.commons.exceptions import APIRequestError | ||
from pyowm.commons.exceptions import NotFoundError as OWMNotFoundError | ||
from requests import Response | ||
from requests import get as requests_get | ||
|
||
|
||
class ProgressBar(Toplevel): | ||
def __init__(self, *args, **kwargs): | ||
tk.Tk.__init__(self, *args, **kwargs) | ||
# Set up window | ||
Toplevel.__init__(self, *args, **kwargs) | ||
self.withdraw() | ||
self.title("Loading...") | ||
self.resizable(False, False) | ||
|
||
# Set up widgets | ||
self.main_frame = Frame(self) | ||
self.main_frame.grid() | ||
|
||
main_label = Label(self.main_frame, text="Loading...", font="Helvetica 15 bold") | ||
main_label.grid(padx=10, pady=10) | ||
|
||
self.progressbar = Progressbar( | ||
self.main_frame, | ||
orient="horizontal", | ||
length=200, | ||
mode="indeterminate", | ||
maximum=4, | ||
) | ||
self.progressbar.grid(padx=10, pady=10) | ||
|
||
self.resize_app() | ||
self.update_idletasks() | ||
self.after_idle(lambda: self.deiconify()) | ||
|
||
def resize_app(self) -> None: | ||
"""Use tkinter to detect the minimum size of the app, get the center of the screen, and place the app there.""" | ||
|
||
# TODO: Make a global function for this to remove boilerplate code | ||
# Update widgets so minimum size is accurate | ||
self.update_idletasks() | ||
|
||
# Get minimum size | ||
minimum_width: int = self.winfo_reqwidth() | ||
minimum_height: int = self.winfo_reqheight() | ||
|
||
# Get center of screen based on minimum size | ||
x_coords = int(self.winfo_screenwidth() / 2 - minimum_width / 2) | ||
y_coords = int(self.wm_maxsize()[1] / 2 - minimum_height / 2) | ||
|
||
self.frame = tk.Frame(self) | ||
self.frame.pack(side="top", fill="both", expand=True) | ||
# Place app and make the minimum size the actual minimum size (non-infringable) | ||
self.geometry(f"{minimum_width}x{minimum_height}+{x_coords}+{y_coords}") | ||
self.wm_minsize(minimum_width, minimum_height) | ||
|
||
self.label = tk.Label(self, text="Hello, world") | ||
self.label.pack(in_=self.frame) | ||
def set_progress(self, progress: int): | ||
self.progressbar.step(progress) | ||
|
||
button1 = tk.Button(self, text="Click to hide label", command=self.hide_label) | ||
button1.pack() | ||
|
||
button2 = tk.Button(self, text="Click to show label", command=self.show_label) | ||
button2.pack() | ||
class App(Tk): | ||
def __init__(self): | ||
super().__init__() | ||
self.bind("<Return>", self.OWMCITY) | ||
self.deiconify() | ||
|
||
def show_label(self, *_): | ||
self.label.lift(self.frame) | ||
def OWMCITY(self, _: Event | None = None) -> None: | ||
"""Get the weather for a given city using the OpenWeatherMap API and display it in a label.""" | ||
|
||
def hide_label(self, *_): | ||
self.label.lower(self.frame) | ||
pb = ProgressBar() | ||
# pb.destroy() | ||
|
||
|
||
if __name__ == "__main__": | ||
app = SampleApp() | ||
app = App() | ||
app.mainloop() |