Search code examples
pythontkintertextboxlabelpyinstaller

Tkinter Label Won't fit in the window after creating an executable with pyinstaller


I made an application with the pyinstaller, but on some machines that will use it, cutting out some labels from the window, in addition two textbox, see the image. How can I solve this? In my machine it fits, in another don't. I think the problem is the place() method, but I don't know why it works in a computer and don't in another.

enter image description here

import tkinter as tk
from tkinter import ttk
import tkinter.font as font
import tkinter.messagebox

class Application(ttk.Frame):   
    def __init__(self, main_window):
        super().__init__(main_window)
        self.place(relwidth=1, relheight=1)
        ttk.Style(main_window)
        font.nametofont("TkTextFont").configure(size=12)
        font.nametofont("TkDefaultFont").configure(size=12)
        #Cabecalho
        ttk.Label(self, text="Requisições", font='arial 18 bold').place(x=150, y=5)
        ttk.Label(self, text="Desligamento", font='arial  18 bold').place(x=142, y=35)
        #Informações usúario
        ttk.Label(self, text="Usuário", font='arial  16 bold').place(x=10, y=100)
        ttk.Label(self, text="Email:", font='arial  14').place(x=10, y=128)
        ttk.Entry(self, width=20).place(x=85, y=128)
        ttk.Label(self, text="Senha:", font='arial  14').place(x=10, y=158)
        ttk.Entry(self,  show="•").place(x=85, y=158)
        #Lote
        ttk.Label(self, text="Lote", font='arial 16 bold').place(x=10, y=190)
        ttk.Label(self, text="Início:", font='arial  14').place(x=10, y=220)
        ttk.Entry(self, width=10).place(x=85, y=220)
        ttk.Label(self, text="Final:", font='arial  14').place(x=10, y=248)
        ttk.Entry(self, width=10).place(x=85, y=250)
        ttk.Label(self,text="dd/mm/aaaa",foreground='red',font='arial 10 italic').place(x=93, y=280)
        ttk.Button(self,text= 'Download').place(x=210, y=215)
        ttk.Button(self,text= 'Planilha').place(x=210, y=247)
        #Informações
        ttk.Label(self, text="Informações",font='arial 16 bold').place(x=10, y=310)
        ttk.Button(self, text="Anexado").place(x=160, y=305)
        ttk.Button(self, text="Pendente").place(x=280, y=305)
        #Montagem listbox
        frame = tk.Frame(main_window)
        frame.pack()
        frame.place(x=10,y=340)
        self.listbox = tk.Listbox(frame,width=45, height=8, selectbackground='#808080', selectmode= 'extended')
        self.listbox.pack(side="left", fill="y")
        self.scrollbar = ttk.Scrollbar(frame, orient="vertical")
        self.scrollbar.config(command=self.listbox.yview)
        self.scrollbar.pack(side="right", fill="y")
        self.listbox.config(yscrollcommand=self.scrollbar.set)
        ttk.Button(self, text="Exibir").place(x=10, y=525)
        ttk.Button(self, text="Aprovada").place(x=160, y=525)
        ttk.Button(self, text="E mail Ponto").place(x=310, y=525)
        ttk.Button(self, text="E mail Pendente", ).place(x=10, y=560)
        # Informações da carta a ser exibida
        ttk.Label(self,text="Requisição:"      , font='arial 14 bold').place(x=450 , y=10)       
        ttk.Label(self,text="Nome:"            , font='arial 14 bold').place(x=450 , y=40)             
        ttk.Label(self,text="Aviso Prévio:"    , font='arial 14 bold').place(x=1000, y=40)        
        ttk.Label(self,text="Motivo:"          , font='arial 14 bold').place(x=650 , y=10)           
        ttk.Label(self,text="Comunicação:"     , font='arial 14 bold').place(x=1010, y=10)     
        ttk.Label(self,text="Desligamento:"    , font='arial 14 bold').place(x=1300, y=10)    
        ttk.Label(self,text="Matrícula:"       , font='arial 14 bold').place(x=1310, y=40)       
        ttk.Label(self,text="Salário:"         , font='arial 14 bold').place(x=450 , y=70)          
        ttk.Label(self,text="Admissão:"        , font='arial 14 bold').place(x=650 , y=70)         
        ttk.Label(self,text="Atualização:"     , font='arial 14 bold').place(x=910, y=70)
        ttk.Label(self,text="Cargo:"           , font='arial 14 bold').place(x=1160, y=70)
        #Montagem Janela Observação
        ttk.Label(self,text="Observações", font='arial 14 bold').place(x=1210, y=100)
        self.obs = tk.Text(self,height=10, width=42, fg="black", bg="white", font=("arial ", 12))
        self.obs.place(x=1210, y=130)
        #Montagem caixa de texto
        ttk.Label(self, text="Carta Inconsistente", font='arial  14 bold').place(x=10, y=600)
        self.texto = tk.Text(self, height=9, width=45, fg="#0911D0", bg="white", font=("arial ", 12), cursor="pencil")
        self.texto.place(x=10, y=630)
        # Botão Enviar email para carta náo ok
        ttk.Button(self, text="Enviar E mail").place(x=10, y=800)
        # Botão Sair
       ttk.Button(self, text="Sair", command=self.quit).place(x=310, y=800)
def main():
    main_window = tk.Tk()
    main_window.title("Desligamentos")
    main_window.state("zoomed")
    app = Application(main_window)
    app.mainloop()  
if __name__=="__main__":
        main()

Solution

  • Just a suggestion, add a new parameter to .place() called anchor. Anchor determines what part of the widget goes to the coordinate specified. For example, if anchor = "center", and the coordinates specified with relx and rely are 0.5 and 0.5 relatively, then the middle of the widget will go to 0.5, 0.5.

    Sometimes the anchor is nw, or top left, and sometimes the widget goes to the side of the screen.

    So, set your anchor to "center", and tell me what happens.

    Hopefully this helps!

    EDIT:

    This would be your code:

    import tkinter as tk
    from tkinter import ttk
    import tkinter.font as font
    import tkinter.messagebox
    
    class Application(ttk.Frame):   
        def __init__(self, main_window):
            super().__init__(main_window)
            self.place(relwidth=1, relheight=1, anchor = "center")
            ttk.Style(main_window)
            font.nametofont("TkTextFont").configure(size=12)
            font.nametofont("TkDefaultFont").configure(size=12)
            #Cabecalho
            ttk.Label(self, text="Requisições", font='arial 18 bold').place(x=150, y=5, anchor = "center")
            ttk.Label(self, text="Desligamento", font='arial  18 bold').place(x=142, y=35, anchor = "center")
            #Informações usúario
            ttk.Label(self, text="Usuário", font='arial  16 bold').place(x=10, y=100, anchor = "center")
            ttk.Label(self, text="Email:", font='arial  14').place(x=10, y=128)
            ttk.Entry(self, width=20).place(x=85, y=128, anchor = "center")
            ttk.Label(self, text="Senha:", font='arial  14').place(x=10, y=158, anchor = "center")
            ttk.Entry(self,  show="•").place(x=85, y=158, anchor = "center")
            #Lote
            ttk.Label(self, text="Lote", font='arial 16 bold').place(x=10, y=190, anchor = "center")
            ttk.Label(self, text="Início:", font='arial  14').place(x=10, y=22, anchor = "center")
            ttk.Entry(self, width=10).place(x=85, y=220, anchor = "center")
            ttk.Label(self, text="Final:", font='arial  14').place(x=10, y=248, anchor = "center")
            ttk.Entry(self, width=10).place(x=85, y=250, anchor = "center")
            ttk.Label(self,text="dd/mm/aaaa",foreground='red',font='arial 10 italic').place(x=93, y=280, anchor = "center")
            ttk.Button(self,text= 'Download').place(x=210, y=215, anchor = "center")
            ttk.Button(self,text= 'Planilha').place(x=210, y=247, anchor = "center")
            #Informações
            ttk.Label(self, text="Informações",font='arial 16 bold').place(x=10, y=310, anchor = "center")
            ttk.Button(self, text="Anexado").place(x=160, y=305, anchor = "center")
            ttk.Button(self, text="Pendente").place(x=280, y=305, anchor = "center")
            #Montagem listbox
            frame = tk.Frame(main_window)
            frame.pack()
            frame.place(x=10,y=340, anchor = "center")
            self.listbox = tk.Listbox(frame,width=45, height=8, selectbackground='#808080', selectmode= 'extended')
            self.listbox.pack(side="left", fill="y")
            self.scrollbar = ttk.Scrollbar(frame, orient="vertical")
            self.scrollbar.config(command=self.listbox.yview)
            self.scrollbar.pack(side="right", fill="y")
            self.listbox.config(yscrollcommand=self.scrollbar.set)
            ttk.Button(self, text="Exibir").place(x=10, y=525, anchor = "center")
            ttk.Button(self, text="Aprovada").place(x=160, y=525, anchor = "center")
            ttk.Button(self, text="E mail Ponto").place(x=310, y=525, anchor = "center")
            ttk.Button(self, text="E mail Pendente", ).place(x=10, y=560, anchor = "center")
            # Informações da carta a ser exibida
            ttk.Label(self,text="Requisição:"      , font='arial 14 bold').place(x=450 , y=10, anchor = "center")       
            ttk.Label(self,text="Nome:"            , font='arial 14 bold').place(x=450 , y=40, anchor = "center")             
            ttk.Label(self,text="Aviso Prévio:"    , font='arial 14 bold').place(x=1000, y=40, anchor = "center")        
            ttk.Label(self,text="Motivo:"          , font='arial 14 bold').place(x=650 , y=10, anchor = "center")           
            ttk.Label(self,text="Comunicação:"     , font='arial 14 bold').place(x=1010, y=10, anchor = "center")     
            ttk.Label(self,text="Desligamento:"    , font='arial 14 bold').place(x=1300, y=10, anchor = "center")    
            ttk.Label(self,text="Matrícula:"       , font='arial 14 bold').place(x=1310, y=40, anchor = "center")       
            ttk.Label(self,text="Salário:"         , font='arial 14 bold').place(x=450 , y=70, anchor = "center")          
            ttk.Label(self,text="Admissão:"        , font='arial 14 bold').place(x=650 , y=70, anchor = "center")         
            ttk.Label(self,text="Atualização:"     , font='arial 14 bold').place(x=910, y=70, anchor = "center")
            ttk.Label(self,text="Cargo:"           , font='arial 14 bold').place(x=1160, y=70, anchor = "center")
            #Montagem Janela Observação
            ttk.Label(self,text="Observações", font='arial 14 bold').place(x=1210, y=100, anchor = "center")
            self.obs = tk.Text(self,height=10, width=42, fg="black", bg="white", font=("arial ", 12))
            self.obs.place(x=1210, y=130, anchor = "center")
            #Montagem caixa de texto
            ttk.Label(self, text="Carta Inconsistente", font='arial  14 bold').place(x=10, y=600, anchor = "center")
            self.texto = tk.Text(self, height=9, width=45, fg="#0911D0", bg="white", font=("arial ", 12), cursor="pencil")
            self.texto.place(x=10, y=630, anchor = "center")
            # Botão Enviar email para carta náo ok
            ttk.Button(self, text="Enviar E mail").place(x=10, y=800, anchor = "center")
            # Botão Sair
            ttk.Button(self, text="Sair", command=self.quit).place(x=310, y=800, anchor = "center")
    def main():
        main_window = tk.Tk()
        main_window.title("Desligamentos")
    
        app = Application(main_window)
        app.mainloop()  
    if __name__=="__main__":
            main()
    

    Please tell me if this works!!