Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.10 KB | None | 0 0
  1.  
  2. import tkinter as tk
  3. import requests
  4. from tkinter import messagebox
  5. from urllib.request import urlopen
  6.  
  7. window = tk.Tk()
  8. window.geometry("900x575")
  9. window.title ("Ascii Art")
  10. window.grid_columnconfigure(0, weight=1)
  11. def check():
  12.  
  13.     try:
  14.         with urlopen('https://www.google.it') as up:
  15.             messagebox.showinfo("Controllo Connessione", "La connessione è attiva!")
  16.  
  17.  
  18.     except BaseException as ex:
  19.         messagebox.showinfo("Controllo Connessione", "La connessione non è attiva!")
  20.         quit()
  21.  
  22.  
  23. def chiusura():
  24.     quit()
  25.  
  26. def centra(window):
  27.     w = window.winfo_screenwidth()
  28.     h = window.winfo_screenheight()
  29.     rw = window.winfo_width()
  30.     rh = window.winfo_height()
  31.     window.geometry('{}x{}+{}+{}'.format(rw, rh, (w-rw)//2, (h-rh)//2))
  32.  
  33. def download_ascii():
  34.     if text_input.get():
  35.         user_input = text_input.get()
  36.         payload = {"text" : user_input}
  37.         response = requests.get("http://artii.herokuapp.com/make",
  38.                                params = payload)
  39.         text_response= response.text
  40.     else:
  41.         text_response = ("Aggiungi una parola o una frase")
  42.  
  43.     textwidget = tk.Text(fg= "white", bg="black")
  44.     textwidget.insert(tk.END, text_response)
  45.     textwidget.grid(row=4, column=0, sticky= "WE", padx=10, pady=10)
  46.  
  47.     credits_label = tk.Label(window, text="API by artti.herokuapp.com", fg = "white", bg = "black")
  48.     credits_label.grid(row=4, columns=1, sticky="S", pady=20)
  49.  
  50.  
  51. window.update()
  52. centra(window)
  53. window.update()
  54. check()
  55.  
  56. welcome_label = tk.Label(window, text="Welcome! Aggiungi la parola da convertire:", font=("Helvetica", 15))
  57. welcome_label.grid(row=0, column=0, sticky="N", padx=20, pady=10)
  58.  
  59. text_input = tk.Entry()
  60. text_input.grid(row=1, column=0, sticky ="WE", padx=10 )
  61.  
  62. download_button = tk.Button(text="Download Ascii Art", command=download_ascii)
  63. download_button.grid(row=2, column=0, sticky="WE", padx=10, pady=10)
  64.  
  65. quit_button= tk.Button(text="Chiudi", command=chiusura)
  66. quit_button.grid(row=3, column=0, sticky="WE", padx=10, pady=10)
  67.  
  68.  
  69.  
  70.  
  71.  
  72. if __name__ == "__main__":
  73.     window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement