Change size of frame in tkinter, which is defined by a class Change size of frame in tkinter, which is defined by a class tkinter tkinter

Change size of frame in tkinter, which is defined by a class


Here is a simple example of how you can use the geometry() method to resize your window. This should help you understand a bit of how it work within a class.

import tkinter as tkclass My_App(tk.Frame):    def __init__(self, parent):        tk.Frame.__init__(self, parent)        # we need to set parent as a class attribute for later use        self.parent = parent         button1 = tk.Button(self.parent, text="Make window larger!", command = self.make_window_bigger)        button1.pack()        button2 = tk.Button(self.parent, text="Make window Smaller!", command = self.make_window_smaller)        button2.pack()    def make_window_bigger(self):        x = self.parent.winfo_height() + 10        y = self.parent.winfo_width() + 10        self.parent.geometry('{}x{}'.format(y, x))    def make_window_smaller(self):        x = self.parent.winfo_height() - 10        y = self.parent.winfo_width() - 10        self.parent.geometry('{}x{}'.format(y, x))root = tk.Tk()My_App(root)root.mainloop()


If you want to resize a Toplevel or the Tk instance, you can use geometry method on the objects:

root.geometry("{}x{}+{}+{}".format(16, 32, 64, 128))#self.geometry("{}x{}+{}+{}".format(16, 32, 64, 128))#self.winfo_toplevel().geometry()("{}x{}+{}+{}".format(16, 32, 64, 128))

If you mean how to resize a Frame, you can simply set its width and height options:

frame = tk.Frame(root, bg='red', width=32, height=23)#self.config(bg='red', width=32, height=23)

and if the frame is non-empty, you should additionally unset its propagation, in order to disallow resizing based on its children widgets' size demands, do so based on the geometry manager used by the children:

frame.pack_propagate(False) # discard either in accordance with the childrenframe.grid_propagate(False)#self.pack_propagate(False) # discard either in accordance with the children#self.grid_propagate(False)