This is not the case if you use PySide instead of PyQt. PySide uses LGPL so your Python code can be whatever license you want.
From PyQt5 vs PySide2: What's the difference between the two Python Qt libraries?:
The key difference in the two versions — in fact the entire reason
PySide2 exists — is licensing. PyQt5 is available under a GPL or
commercial license, and PySide2 under a LGPL license.
If you are planning to release your software itself under the GPL, or
you are developing software which will not be distributed, the GPL
requirement of PyQt5 is unlikely to be an issue. However, if you plan
to distribute your software without distributing the source you will
either need to purchase a commercial license from Riverbank for PyQt5
or use PySide2.
The LGPL license does not require you to share the source code of your
own applications, even if they are bundled with PySide2.