Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set window dimensions in Tkinter, Python 3

I've done plenty of Tkinter Python apps before, but I've never come across this problem:

How do you set the dimensions of the initial (root) window in Tkinter with Python 3?

I've come across this question which details the answer for Python 2.7, but Tkinter has been updated for Python 3 so the solution doesn't work.

Here's the obnoxious bit of code:

class Application(tk.Frame):    
    def __init__(self, master=None):
        tk.Frame.__init__(self,master)
        self.grid()
        self.createWidgets()
        master.minsize(width=500,height=500)

app = Application()
app.master.title("MFPA")
app.mainloop()

The master.minsize() line comes from the referenced question, but since my master object is None, the method doesn't exist.

The second solution there also doesn't work, as it relies on having called the tk.Tk() method to start with, whereas I am using the updated Tkinter and this new method of creating windows.

like image 381
ArtOfCode Avatar asked Sep 05 '26 15:09

ArtOfCode


1 Answers

The tk.Frame.__init__ call should automatically find the master for you and assign it to an attribute of the object. Try:

    self.master.minsize(width=500,height=500)
like image 184
Kevin Avatar answered Sep 07 '26 04:09

Kevin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!