I am working on a Tkinter GUI and I want to add window sizing and positioning control in its separate class. My structure is like so:
class MainApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.winsize= WinSize(container, 700, 500, 650, 450, True, True)
I want WinSize
to set the geometry of the main application as well as handle
the minsize
, resizeable
in the WinSize class.
class WinSize:
def __init__(self, container, width, height, minx, miny, sizeablex, sizeabley):
self.container = container
self.width = width
self.height = height
self.minx = minx
self.miny = miny
self.sizeablex = sizeablex
self.sizeabley = sizeabley
self.ws = self.container.winfo_screenwidth()
self.hs = self.container.winfo_screenheight()
self.xpos = (self.ws / 2) - (self.width / 2)
self.ypos = (self.hs / 2) - (self.height / 2)
I have been searching extensively and found no solution/guidance on how to get those implemented in the WinSize
class for that particular instance and/or Frame.
I want to use the same class to be able to set size and other attributes to pop-up messages/Frames that will display other information.
The main GUI class is taken from @Bryan Oakley's famous example: https://stackoverflow.com/a/7557028/7703610
How do I call the geometry
, minsize
and resizeable
from Tk without having to inherit Tk again in my WinSize class and then apply it to that particular instance?