I created a package. It's a function I need to use in almost every Tkinter project of mine. It centers my Tkinter window on the screen of the user. How do I make it like a global package like "import pandas" or "import math"?
This is the code for my package:
MyPkg.py
def Centre(NameOfTkinterWindow,Width,Height):#This function Centres the Tkinter window on the screen
scrwdth = NameOfTkinterWindow.winfo_screenwidth()
scrhgt = NameOfTkinterWindow.winfo_screenheight()
xLeft = int((scrwdth/2) - (Width/2))
yTop = int((scrhgt/2) - (Height/2))
NameOfTkinterWindow.geometry(str(Width) + "x" + str(Height) + "+" + str(xLeft) + "+" + str(yTop))
This is my Tkinter project that I am working on: main.py
from tkinter import *
from MyPkg import * #importing my custom built package
main=Tk()
main.title("Test Taking App")
Centre(main,500,500) #A function from my Package
main.iconbitmap("D:\Coding\Python Scripts\PDF Convertor App\DevenIcon.ico")
main.mainloop()
Everything is working as intended:
But I want to make it so that I don't need to have this MyPkg.py in the same folder as my Tkinter projects as I make many different softwares and each one has their own folder.
I want to be able to import it anywhere on my computer from any directory. What can I try next?