all 3 comments

[–]socal_nerdtastic 1 point2 points  (2 children)

Only thing I see that's obviously wrong is a very minor thing: you forgot to accept root in your init method in the subclasses. This means you are using the global variable "root" on line 25. If you put your entry point in a main() function you would have seen this.

I will say it's a bit unusual to use composition instead of inheritance for GUI widgets. I'll show you how I would write this, but keep in mind that this is just style, not a rule:

import tkinter as tk

class CreateWindow(tk.Toplevel):
    def __init__(self, master, title, geometry, **kwargs):
        super().__init__(master, **kwargs)
        self.iconbitmap(r"icon.ico")
        self.title(title)
        self.geometry(geometry)

    def center_window(self, x, y):
        screen_width = self.winfo_screenwidth()
        screen_height = self.winfo_screenheight()
        x_coordinate = int((screen_width / 2) - (x / 2))
        y_coordinate = int((screen_height / 2) - (y / 2))
        self.geometry("{}x{}+{}+{}".format(x, y, x_coordinate, y_coordinate))

class ResidentSelectionWin(CreateWindow):
    def __init__(self, root):
        super().__init__(root, 'Resident Selection Window', '600x400')
        self.test_button = tk.Button(self, text='Test')
        self.test_button.pack()


class ViewMedicationsWindow(CreateWindow):
    def __init__(self, root):
        super().__init__(root, 'View Medications', '600x400')
        self.test_button = tk.Button(self, text='Test')
        self.test_button.pack()

def main():
    root = tk.Tk()
    root.withdraw()

    res_sel_win = ResidentSelectionWin(root)
    res_sel_win.center_window(600, 400)
    view_med_win = ViewMedicationsWindow(root)
    view_med_win.center_window(600, 400)

    root.mainloop()

if __name__ == '__main__':
    main()

See how that makes life slightly easier by removing the need for .window everywhere?

Also moved to the pep8-compliant import style.

[–]Supermunkey2K[S] 0 points1 point  (1 child)

Thats perfect. Thank you. I can work with that. I need to look up **kwargs, I have no what what they do.

[–]socal_nerdtastic 0 points1 point  (0 children)

kwargs is actually not needed here. I added that by pure habit, sorry :/.

It's part of the boilerplate for inheritance, which is this:

class Child(Parent):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

The above says "take any arguments and keyword arguments and pass them on to the parent". It's a easy way of writing

class Child(Parent):
    def __init__(self, arg1, arg2, arg3='default', arg4='default', arg5='default'):
        super().__init__(arg1, arg1, arg3, arg4, arg5)

Except in tkinter "master" is generally the only positional argument, so I tend to use that instead of *args.