Actually i made a GUI.py and wanted to make it a module
the directory is like this:
\lib\site-packages\GUI\ __init__.py --> this file is empty
\lib\site-packages\GUI\__main__.py --> this file contains the classes
the code in __main__.py is:
from tkinter import *
class Window():
def __init__(self):
super(window,self).__init__(self,*args,**kwargs)
self.main = Tk()
def title(self,title="tk"):
self.main.title(title)
def run(self):
self.main.mainloop()
the code in another file is:
from GUI import Window
a = Window()
a.run()
However this generates Error:
ImportError: cannot import name 'Window' from 'GUI' (C:\Users\ADMIN\AppData\Local\Programs\Python\Python39\lib\site-packages\GUI\__init__.py)
How can i fix this? thanx in advance!
Oh sorry to trouble you i found out my mistake!
I made them opposite
what i did:
__main__.py
to __init__.py
and __init__.py
to __main__.py
@Tabaraei
Said i added from __init__ import *
in __main__.py
Fixed My problem Thank you all!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.