Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import copy
- import csv
- import datetime
- import os
- import pickle
- from tkinter import *
- from tkinter import messagebox as msg
- import tkinter as tk
- import ntplib
- import requests
- from PIL import ImageTk, Image
- from matplotlib import pyplot as plt
- class ParentWindow(Tk): # classe per la finestra delle regioni
- # attributi
- path = os.getcwd() + "\\assets\\" # path directory script-->dinamica
- w = 0 # larghezza finestra
- h = 0 # altezza finestra
- tipo = "regione" # per il print di aiuto all'utente
- regioni = []
- # metodi
- def __init__(self, master): # inizializzazione finestra
- print("Costruttore richiamato")
- self.master = master
- self.master.title("Analizzatore Covid-19")
- self.master.tk.call('wm', 'iconphoto', master._w, PhotoImage(file=os.path.join(self.path + "favicon.png")))
- self.master.resizable(False, False)
- self.master.focus_set()
- self.master.bind("<Escape>", lambda e: (e.widget.withdraw(), e.widget.quit()))
- self.w = 585
- self.h = 734
- self.regioni = ["Valle D'Aosta", 50, 100, "Piemonte", 57, 150, "Trentino", 220, 55, "Friuli", 300, 75, "Veneto",
- 235, 125, "Lombardia", 150, 120, "Liguria", 110, 210, "Emilia-Romagna", 215, 185, "Toscana",
- 215, 260, "Umbria", 275, 290, "Marche", 320, 265, "Lazio", 275, 350, "Abruzzo", 355, 335,
- "Molise", 380, 380, "Puglia", 435, 400, "Campania", 390, 425, "Basilicata", 460, 450,
- "Calabria", 490, 530, "Sicilia", 375, 650, "Sardegna", 105, 475]
- x = (master.winfo_screenwidth() / 2) - (self.w / 2)
- y = (master.winfo_screenheight() / 2) - (self.h / 2)
- master.geometry('%dx%d+%d+%d' % (self.w, self.h, x, y))
- def creaScenario(self, nomeImmagine):
- canvas = Canvas(width=585, height=734, bg='white', relief=FLAT)
- canvas.pack(expand=YES, fill=BOTH)
- bg = ImageTk.PhotoImage(file=self.path + nomeImmagine)
- canvas.create_image(2, 2, image=bg, anchor=NW)
- canvas.create_text(455, 180, fill="darkblue", font="Times 15 italic bold", text="Seleziona una " + self.tipo)
- self.caricaBottoni(canvas, self.regioni)
- print("Scenario creato")
- mainloop()
- def caricaBottoni(self, canvas, lista):
- for i in range(0, len(lista), 3): # caricamento bottoni sullo scenario
- self.creaBottone(canvas, lista[i], lista[i + 1], lista[i + 2])
- def creaBottone(self, canvas, regione, x, y):
- bottone = canvas.create_text(x, y, fill="black", font="Times 11", text=regione)
- canvas.tag_bind(bottone, '<Button-1>', lambda event, arg=regione: self.creaChildWindow(event, arg))
- def creaChildWindow(self,event,regione):
- print(regione)
- self.nascondi()
- new = tk.Toplevel(self.master)
- child = ChildWindow(new)
- child.regione=regione
- child.creaScenario("favicon.png")
- def callback(self, event, regione):
- print(regione)
- def nascondi(self):
- self.master.withdraw()
- class ChildWindow(ParentWindow): # classe per le finestre delle province
- tipo = "provincia"
- regione = ""
- provincia=""
- def debug(self):
- print("funziona!")
- def caricaBottoni(self, canvas, lista):
- pass
- root = Tk()
- mainWindow = ParentWindow(root)
- mainWindow.creaScenario("regioni_cropped.png")
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement