Home>

I have written a program and want to make it executable usingpyinstaller, but unfortunately, when starting the program, some window sizes are incorrect, because I set the window geometry like this:self.geometry('+{}+{}'.format(w, h))In this example, the main thing is that the dimensions of the window are set automatically.

When I run the program through IDEL, everything is displayed correctly, but when I run the .exe file, the dimensions move out. For everything to be fine, I need to know the automatic sizes given to the window. How can this be implemented?

  • Answer # 1

    It's much simpler, use the wm_maxsize() method

    welcome to This Club in Russian! please try to leave a little more detailed answers. You can add to your answer by clicking edit.

    aleksandr barakin2022-01-22 21:17:49
  • Answer # 2

    You can stretch an invisible widget to fill the screen and measure its dimensions using winfo_height and winfo_width. Here is an example for a button:

    import tkinter as tk
    def func():
        x= button_place.winfo_width()
        y= button_place.winfo_height()
        print(x, y)
    root= tk.Tk()
    root.geometry('600x500')
    button_place= tk.Button(root, text='', font='Times 15', command=func)
    button_place.place(w=600, h=500)
    root.mainloop()
    

    But it's usually used to size widgets. To determine the screen, you just needroot.geometry(). The first example was given just for additional information, you may need

  • Answer # 3

    Use the methodgeometry()classtkinter.Tk(), example:

    import tkinter as tk
    root= tk.Tk()
    print(root.geometry())
    

    Everything works, just add brackets after geometry, otherwise it gives nonsense

    DGDays2022-01-23 10:45:14