Reputation: 13
Python: 3.8.0
I Want to make one python file for functions and other for the main code
EXAMPLE
file1.py [MY MAIN FILE]
import tkinter as tk
from tkinter import *
import file2
win = tk.Tk()
labeltest = Label(win, text="Hello World")
win.mainloop()
file2.py [the one I want the functions in]
import file1
def testfunc():
labeltest.pack()
and I don't know why it is giving me a error please help
Upvotes: 1
Views: 67
Reputation: 116
what you are trying to do is known as circular import which is not allowed in python.to solve this its either you: 1: merge the two files(but you need two program files ) 2: which i think is your solution , you call the import when need in the particular statement.
file1.py becomes
import tkinter as tk
from tkinter import *
win = tk.Tk()
labeltest = Label(win, text="Hello World")
win.mainloop()
file2 becomes:
def testfunc():
import file1
file1.labeltest.pack()
Hit me up if you encounter more probs
Upvotes: 2