Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from PIL import Image, ImageTk
- def on_button_click(button_text):
- print(f"Il pulsante {button_text} è stato creato")
- # creazione finestra
- # -------------------------------------------------------------------------------------------
- window = tk.Tk() # creazione finestra
- window.geometry("1000x600") # definizione dimensioni della finestra
- window.title("INTERFACCIA LADDER") # definizione titolo finestra
- window.resizable(False, False) # dimensioni non personalizzabili dall'utente
- window.configure(background="white") # gestisco la configurazione dell'interfaccia estetica
- # -------------------------------------------------------------------------------------------
- # creazione canvas di gestione pulsanti principali
- # -------------------------------------------------------------------------------------------
- buttons = tk.Canvas(window, width=990, height=30, bg="white")
- buttons.place(x=3, y=1)
- # -------------------------------------------------------------------------------------------
- # inserimento pulsanti principali nel canvas iniziale
- # -------------------------------------------------------------------------------------------
- # scelgo le dimensioni in caratteri dei pulsanti (se voglio più caratteri modifico width)
- # e di conseguenza devo rivedere le loro coordinate nella lista di tuple in basso
- standards_button_width = 18
- standards_button_height = 1
- # posso aggiungere dei pulsanti con un loro nome e la loro coordinata x, in questo
- # caso la distanza scelta è di 145 pixel in x
- pulsanti_data = [("aggiungi un contatto", 75), ("pulsante 1", 220), ("pulsante 2", 365)]
- for text, x_coord in pulsanti_data:
- pulsante = tk.Button(buttons, text=text, command=lambda t=text: on_button_click(t), width=standards_button_width, height=standards_button_height)
- buttons.create_window(x_coord, 17, window=pulsante)
- # -------------------------------------------------------------------------------------------
- # creazione canvas dove verranno inseriti i + per inserire nuovi network
- # ci saranno un massimo di 8 network e ogni network avrà al massimo 3
- # collegamenti in serie e 2 in parallelo
- # -------------------------------------------------------------------------------------------
- number_networks = tk.Canvas(window, width=990, height=2400, bg="white")
- number_networks.place(x=3, y=33)
- # scrollbar del canvas number_networks
- # -------------------------------------------------------------------------------------------
- def on_configure(event):
- number_networks.configure(scrollregion=number_networks.bbox("all"))
- scrollbar = tk.Scrollbar(window, orient="vertical", command=number_networks.yview)
- scrollbar.pack(side="right", fill="y")
- number_networks.configure(yscrollcommand=scrollbar.set)
- number_networks.bind("<Configure>", on_configure)
- # -------------------------------------------------------------------------------------------
- #riempimento canvas con dei canvas
- buttons_add_width = 1
- buttons_add_height = 1
- #network 1
- network_1 = tk.Canvas(number_networks, width=970, height=280, bg="lightblue")
- network_1.place(x=3, y=43)
- pulsante_add = tk.Button(network_1, width=buttons_add_width, height=buttons_add_height, bg="blue", text="+")
- pulsante_add.place(x=10, y=125)
- #network 2
- network_2 = tk.Canvas(number_networks, width=970, height=280, bg="lightblue")
- network_2.place(x=3, y=333)
- pulsante_add = tk.Button(network_2, width=buttons_add_width, height=buttons_add_height, bg="blue", text="+")
- pulsante_add.place(x=10, y=125)
- #network 3
- network_3 = tk.Canvas(number_networks, width=970, height=280, bg="lightblue")
- network_3.place(x=3, y=623)
- pulsante_add = tk.Button(network_3, width=buttons_add_width, height=buttons_add_height, bg="blue", text="+")
- pulsante_add.place(x=10, y=125)
- #network 4
- network_4 = tk.Canvas(number_networks, width=970, height=280, bg="lightblue")
- network_4.place(x=3, y=913)
- pulsante_add = tk.Button(network_4, width=buttons_add_width, height=buttons_add_height, bg="blue", text="+")
- pulsante_add.place(x=10, y=125)
- # -------------------------------------------------------------------------------------------
- if __name__ == "__main__": # chiamo la funzione principale main
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment