Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    [Python] Finestra non cenrata in Tkinter

    ciao!

    sto cercando di avviare la finestra principale centrata in tkinter.
    questo il codice:
    codice:
    import tkinter as tk
    
    if __name__ == '__main__':
        root = tk.Tk()
        root.title('MPQrcode')
    
        windowWidth = root.winfo_reqwidth()
        windowHeight = root.winfo_reqheight()
    
        positionRight = int(root.winfo_screenwidth() / 2 - windowWidth / 2)
        positionDown = int(root.winfo_screenheight() / 2 - windowHeight / 2)
        root.geometry("{}x{}+{}+{}".format(700, 700, positionRight, positionDown))
    
        root.resizable(0, 0)
        root.mainloop()
    in sostanza non è centrata.
    dove sbaglio??

  2. #2
    ok risolto:

    codice:
    import tkinter as tk
    
    if __name__ == '__main__':
        root = tk.Tk()
        root.title('MPQrcode')
    
        w = 700
        h = 700
        ws = root.winfo_screenwidth()
        hs = root.winfo_screenheight()
        x = (ws / 2) - (w / 2)
        y = (hs / 2) - (h / 2)
        root.geometry("{}x{}+{}+{}".format(w, h, int(x), int(y)))
    
        lblTitle = tk.Label(root, text="Scegli cosa inserire")
        lblTitle.grid(row=0, column=0, sticky='W', pady=2)
    
        root.resizable(0, 0)
        root.mainloop()

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.