Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import requests
- from tkinter import messagebox
- from urllib.request import urlopen
- window = tk.Tk()
- window.geometry("900x575")
- window.title ("Ascii Art")
- window.grid_columnconfigure(0, weight=1)
- def check():
- try:
- with urlopen('https://www.google.it') as up:
- messagebox.showinfo("Controllo Connessione", "La connessione è attiva!")
- except BaseException as ex:
- messagebox.showinfo("Controllo Connessione", "La connessione non è attiva!")
- quit()
- def chiusura():
- quit()
- def centra(window):
- w = window.winfo_screenwidth()
- h = window.winfo_screenheight()
- rw = window.winfo_width()
- rh = window.winfo_height()
- window.geometry('{}x{}+{}+{}'.format(rw, rh, (w-rw)//2, (h-rh)//2))
- def download_ascii():
- if text_input.get():
- user_input = text_input.get()
- payload = {"text" : user_input}
- response = requests.get("http://artii.herokuapp.com/make",
- params = payload)
- text_response= response.text
- else:
- text_response = ("Aggiungi una parola o una frase")
- textwidget = tk.Text(fg= "white", bg="black")
- textwidget.insert(tk.END, text_response)
- textwidget.grid(row=4, column=0, sticky= "WE", padx=10, pady=10)
- credits_label = tk.Label(window, text="API by artti.herokuapp.com", fg = "white", bg = "black")
- credits_label.grid(row=4, columns=1, sticky="S", pady=20)
- window.update()
- centra(window)
- window.update()
- check()
- welcome_label = tk.Label(window, text="Welcome! Aggiungi la parola da convertire:", font=("Helvetica", 15))
- welcome_label.grid(row=0, column=0, sticky="N", padx=20, pady=10)
- text_input = tk.Entry()
- text_input.grid(row=1, column=0, sticky ="WE", padx=10 )
- download_button = tk.Button(text="Download Ascii Art", command=download_ascii)
- download_button.grid(row=2, column=0, sticky="WE", padx=10, pady=10)
- quit_button= tk.Button(text="Chiudi", command=chiusura)
- quit_button.grid(row=3, column=0, sticky="WE", padx=10, pady=10)
- if __name__ == "__main__":
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement