Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.46 KB | None | 0 0
  1. import copy
  2. import csv
  3. import datetime
  4. import os
  5. import pickle
  6. from tkinter import *
  7. from tkinter import messagebox as msg
  8. import tkinter as tk
  9.  
  10. import ntplib
  11. import requests
  12. from PIL import ImageTk, Image
  13. from matplotlib import pyplot as plt
  14.  
  15.  
  16. class ParentWindow(Tk):  # classe per la finestra delle regioni
  17.     # attributi
  18.     path = os.getcwd() + "\\assets\\"  # path directory script-->dinamica
  19.     w = 0  # larghezza finestra
  20.     h = 0  # altezza finestra
  21.     tipo = "regione"  # per il print di aiuto all'utente
  22.     regioni = []
  23.  
  24.     # metodi
  25.     def __init__(self, master):  # inizializzazione finestra
  26.         print("Costruttore richiamato")
  27.         self.master = master
  28.         self.master.title("Analizzatore Covid-19")
  29.         self.master.tk.call('wm', 'iconphoto', master._w, PhotoImage(file=os.path.join(self.path + "favicon.png")))
  30.         self.master.resizable(False, False)
  31.         self.master.focus_set()
  32.         self.master.bind("<Escape>", lambda e: (e.widget.withdraw(), e.widget.quit()))
  33.         self.w = 585
  34.         self.h = 734
  35.         self.regioni = ["Valle D'Aosta", 50, 100, "Piemonte", 57, 150, "Trentino", 220, 55, "Friuli", 300, 75, "Veneto",
  36.                         235, 125, "Lombardia", 150, 120, "Liguria", 110, 210, "Emilia-Romagna", 215, 185, "Toscana",
  37.                         215, 260, "Umbria", 275, 290, "Marche", 320, 265, "Lazio", 275, 350, "Abruzzo", 355, 335,
  38.                         "Molise", 380, 380, "Puglia", 435, 400, "Campania", 390, 425, "Basilicata", 460, 450,
  39.                         "Calabria", 490, 530, "Sicilia", 375, 650, "Sardegna", 105, 475]
  40.  
  41.         x = (master.winfo_screenwidth() / 2) - (self.w / 2)
  42.         y = (master.winfo_screenheight() / 2) - (self.h / 2)
  43.  
  44.         master.geometry('%dx%d+%d+%d' % (self.w, self.h, x, y))
  45.  
  46.     def creaScenario(self, nomeImmagine):
  47.         canvas = Canvas(width=585, height=734, bg='white', relief=FLAT)
  48.         canvas.pack(expand=YES, fill=BOTH)
  49.         bg = ImageTk.PhotoImage(file=self.path + nomeImmagine)
  50.         canvas.create_image(2, 2, image=bg, anchor=NW)
  51.  
  52.         canvas.create_text(455, 180, fill="darkblue", font="Times 15 italic bold", text="Seleziona una " + self.tipo)
  53.  
  54.         self.caricaBottoni(canvas, self.regioni)
  55.  
  56.         print("Scenario creato")
  57.  
  58.         mainloop()
  59.  
  60.     def caricaBottoni(self, canvas, lista):
  61.         for i in range(0, len(lista), 3):  # caricamento bottoni sullo scenario
  62.             self.creaBottone(canvas, lista[i], lista[i + 1], lista[i + 2])
  63.  
  64.     def creaBottone(self, canvas, regione, x, y):
  65.         bottone = canvas.create_text(x, y, fill="black", font="Times 11", text=regione)
  66.         canvas.tag_bind(bottone, '<Button-1>', lambda event, arg=regione: self.creaChildWindow(event, arg))
  67.  
  68.     def creaChildWindow(self,event,regione):
  69.         print(regione)
  70.         self.nascondi()
  71.         new = tk.Toplevel(self.master)
  72.         child = ChildWindow(new)
  73.         child.regione=regione
  74.         child.creaScenario("favicon.png")
  75.  
  76.     def callback(self, event, regione):
  77.         print(regione)
  78.  
  79.     def nascondi(self):
  80.         self.master.withdraw()
  81.  
  82.  
  83. class ChildWindow(ParentWindow):  # classe per le finestre delle province
  84.     tipo = "provincia"
  85.     regione = ""
  86.     provincia=""
  87.  
  88.  
  89.     def debug(self):
  90.         print("funziona!")
  91.  
  92.     def caricaBottoni(self, canvas, lista):
  93.         pass
  94.  
  95.  
  96.  
  97. root = Tk()
  98. mainWindow = ParentWindow(root)
  99. mainWindow.creaScenario("regioni_cropped.png")
  100. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement