I am practicing to create a small project with different files to have a clean code. I want to show yellow frame from (fyellow.py) into (main.py) and input a label into it from (funbut.py) using Button
's function. This is my code example: (3 Python files - main.py, fyellow.py, and funbut.py)
main.py
from tkinter import * from fyellow import * import funbut root = Tk() root.geometry("500x500") # Show Yellow Frame into Main from (fyellow.py) myframe = Frameyellow(root) # Button with command - But_fun1 but1 = Button(root, text="Text",command=funbut.but_fun1) but1.pack() root.mainloop()
funbut.py
from tkinter import * from fyellow import * # Function of Button (but1) PROBLEM HERE! (ERROR - 'framey' is not defined) def but_fun1(): label1 = Label(framey,text="LabelText") label1.place(x=10,y=10)
fyellow.py
from tkinter import * class Frameyellow: def __init__(self,rootyellow): self.rootyellow = rootyellow self.framey = Frame(rootyellow, width=200,height=200,bg="yellow") self.framey.pack()
Could explain what can I do to use the self.framey
from file (fyellow.py) to avoid
error 'framey' is not defined
?