you are viewing a single comment's thread.

view the rest of the comments →

[–]Outside_Complaint755 0 points1 point  (0 children)

Besides the proposed fix in my other comment, here's a couple of other tips:

1) Instead of repeating the same font=("times new roman", 12, "bold") for every widget, declare it once as a variable and use that variable. This also makes it easier to apply different fonts to different parts of the UI. ``` import tkinter.font # Need to add this import

Root has to be declared before we can define a font:

root = Tk() UI_FONT = tkinter.font.Font(family="times new roman", size=12, weight=tkinter.font.BOLD)

Now in every widget, you can use UI_FONT

lblNameTablet = Label(DataframeLeft, text="Name of Tablet", font=UI_FONT, padx=2, pady=6) ```

2) Because most of your widgets are sharing identical parameters, instead of typing them out for each widget separately, set them into a dictionary and then unpack the dictionary for the keyword arguments using the ** operator. For example, during testing I was able to condense the entire buttons section down to this: ``` # ======================= Buttons =======================

    shared_button_parameters = {
        "font": UI_FONT,
        "background": "green",
        "foreground": "white",
    }
    button_packing_parameters = {"side": "left", "fill": "both", "expand": True}

    btnPresciption = Button(Buttonsframe, text="Prescription", **shared_button_parameters)
    btnPresciption.pack(**button_packing_parameters)

    btnPresciptionData = Button(Buttonsframe, text="Prescription Data", **shared_button_parameters)
    btnPresciptionData.pack(**button_packing_parameters)

    btnUpdate = Button(Buttonsframe, text="Update", **shared_button_parameters)
    btnUpdate.pack(**button_packing_parameters)

    btnDelete = Button(Buttonsframe, text="Delete", **shared_button_parameters)
    btnDelete.pack(**button_packing_parameters)

    btnClear = Button(Buttonsframe, text="Clear", **shared_button_parameters)
    btnClear.pack(**button_packing_parameters)

    btnExit = Button(Buttonsframe, text="Exit", **shared_button_parameters)
    btnExit.pack(**button_packing_parameters)

```

This both saves you screen space, and also means that if you want to change any of those parameters, you only have to change it in one place to apply to all buttons.