Salve a tutti,
sto giocando con la UI di python per capire come funzione e prendere dimestichezza. Mi sono imbattuto in questa cosa strana: quando inserisco in un Label() il metodo .pack() ed in un'altro Label() il metodo grid() la Virtual Machine di python non mi crea la finestra, mentre se faccio restare solo il metodo .pack() o grid() la finestra viene stampata a video. da premettere che il compilatore non mi stampa nessuna eccezione o errore.

Questo è il link per visualizzare il codice:




  1. from tkinter import *
  2. root = Tk()
  3. setWidth = 400
  4. setHeight = 400
  5. screenWidth = root.winfo_screenwidth()
  6. screenHeight = root.winfo_screenheight()
  7. rootMarginWidth = round((screenWidth - setWidth) / 2)
  8. rootMarginHeight = round((screenHeight - setHeight) / 2)
  9. root.resizable(width=FALSE, height=FALSE)
  10. setGeometry = str(setWidth) + 'x' + str(setHeight) + '+' + str(rootMarginWidth) + '+' + str(rootMarginHeight)
  11. root.title('Titolo')
  12. root.geometry(setGeometry)
  13. root.configure(background='#333333')
  14. lbl1 = Label(root, text="Test Label con metodo grid()", fg='#FFFFFF', bg='#222222',font=("Arial",11))
  15. lbl1.grid(row=0)
  16. lbl2 = Label(root, text="Test label 2 con metodo grid()", fg='#FFFFFF', bg='#222222',font=("Arial",11))
  17. lbl2.grid(row=1)
  18. # se decommento questo snippet di codice il compilatore non crea la finestra
  19. #statusBar = Label(root, text="Test label 3 con il metodo pack()", fg='#FFFFFF', bg='#222222',
  20. # font=("Arial", 11))
  21. #statusBar.pack(side=BOTTOM, fill=X)
  22. root.mainloop()