Official_Lusi

Untitled

Nov 16th, 2023
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | Help | 0 0
  1. import tkinter as tk
  2. from PIL import Image, ImageTk
  3.  
  4. def on_button_click(button_text):
  5. print(f"Il pulsante {button_text} è stato creato")
  6.  
  7.  
  8. # creazione finestra
  9. # -------------------------------------------------------------------------------------------
  10. window = tk.Tk() # creazione finestra
  11. window.geometry("1000x600") # definizione dimensioni della finestra
  12. window.title("INTERFACCIA LADDER") # definizione titolo finestra
  13. window.resizable(False, False) # dimensioni non personalizzabili dall'utente
  14. window.configure(background="white") # gestisco la configurazione dell'interfaccia estetica
  15. # -------------------------------------------------------------------------------------------
  16.  
  17. # creazione canvas di gestione pulsanti principali
  18. # -------------------------------------------------------------------------------------------
  19. buttons = tk.Canvas(window, width=990, height=30, bg="white")
  20. buttons.place(x=3, y=1)
  21. # -------------------------------------------------------------------------------------------
  22.  
  23. # inserimento pulsanti principali nel canvas iniziale
  24. # -------------------------------------------------------------------------------------------
  25. # scelgo le dimensioni in caratteri dei pulsanti (se voglio più caratteri modifico width)
  26. # e di conseguenza devo rivedere le loro coordinate nella lista di tuple in basso
  27. standards_button_width = 18
  28. standards_button_height = 1
  29. # posso aggiungere dei pulsanti con un loro nome e la loro coordinata x, in questo
  30. # caso la distanza scelta è di 145 pixel in x
  31. pulsanti_data = [("aggiungi un contatto", 75), ("pulsante 1", 220), ("pulsante 2", 365)]
  32.  
  33. for text, x_coord in pulsanti_data:
  34. pulsante = tk.Button(buttons, text=text, command=lambda t=text: on_button_click(t), width=standards_button_width, height=standards_button_height)
  35. buttons.create_window(x_coord, 17, window=pulsante)
  36.  
  37. # -------------------------------------------------------------------------------------------
  38.  
  39. # creazione canvas dove verranno inseriti i + per inserire nuovi network
  40. # ci saranno un massimo di 8 network e ogni network avrà al massimo 3
  41. # collegamenti in serie e 2 in parallelo
  42. # -------------------------------------------------------------------------------------------
  43.  
  44. number_networks = tk.Canvas(window, width=990, height=2400, bg="white")
  45. number_networks.place(x=3, y=33)
  46.  
  47. # scrollbar del canvas number_networks
  48. # -------------------------------------------------------------------------------------------
  49. def on_configure(event):
  50. number_networks.configure(scrollregion=number_networks.bbox("all"))
  51.  
  52. scrollbar = tk.Scrollbar(window, orient="vertical", command=number_networks.yview)
  53. scrollbar.pack(side="right", fill="y")
  54. number_networks.configure(yscrollcommand=scrollbar.set)
  55. number_networks.bind("<Configure>", on_configure)
  56. # -------------------------------------------------------------------------------------------
  57.  
  58. #riempimento canvas con dei canvas
  59. buttons_add_width = 1
  60. buttons_add_height = 1
  61. #network 1
  62. network_1 = tk.Canvas(number_networks, width=970, height=280, bg="lightblue")
  63. network_1.place(x=3, y=43)
  64. pulsante_add = tk.Button(network_1, width=buttons_add_width, height=buttons_add_height, bg="blue", text="+")
  65. pulsante_add.place(x=10, y=125)
  66.  
  67. #network 2
  68. network_2 = tk.Canvas(number_networks, width=970, height=280, bg="lightblue")
  69. network_2.place(x=3, y=333)
  70. pulsante_add = tk.Button(network_2, width=buttons_add_width, height=buttons_add_height, bg="blue", text="+")
  71. pulsante_add.place(x=10, y=125)
  72.  
  73. #network 3
  74. network_3 = tk.Canvas(number_networks, width=970, height=280, bg="lightblue")
  75. network_3.place(x=3, y=623)
  76. pulsante_add = tk.Button(network_3, width=buttons_add_width, height=buttons_add_height, bg="blue", text="+")
  77. pulsante_add.place(x=10, y=125)
  78.  
  79. #network 4
  80. network_4 = tk.Canvas(number_networks, width=970, height=280, bg="lightblue")
  81. network_4.place(x=3, y=913)
  82. pulsante_add = tk.Button(network_4, width=buttons_add_width, height=buttons_add_height, bg="blue", text="+")
  83. pulsante_add.place(x=10, y=125)
  84.  
  85. # -------------------------------------------------------------------------------------------
  86.  
  87. if __name__ == "__main__": # chiamo la funzione principale main
  88. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment