It turned out a big code in which it is difficult to navigate, can it be divided into several separate sections, put into separate files, and refer to them when launching the main code?

Closed due to the fact that the question is too general for the participants jfs , Suvitruf , 0xdb , Sergey Glazirin , Alex Chermenin 30 May '18 at 11:45 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • If you are interested in the question of whether this can be done, then yes you can. Just import a file with a different code into the main one. - Twiss
  • Thanks for the answer, could you show the implementation of this function with a simple code example? - Semyon
  • try to narrow the question. You do not know how to use functions from another module in Python? Example: How can I access ONLY ONE function in a python file in a linux console? - jfs

1 answer 1

Well for example 2 files

xay.py :

 import tkinter as tk import quest class Main(tk.Tk): def __init__(self): super().__init__() label = tk.Label(self, text="Какой текст из основного файла").pack() button = tk.Button(self, text="кнопка", command=quest.Top).pack() if __name__ == "__main__": Main().mainloop() 

and quest.py :

 import tkinter as tk class Top(tk.Toplevel): def __init__(self): super().__init__() label = tk.Label(self, text="Текст который изображен в другом файле").pack() if __name__ == "__main__": Top().mainloop() 

enter image description here

  • Thank you so much) - Semyon