【发布时间】:2021-10-31 17:30:24
【问题描述】:
我正在练习创建一个包含不同文件的小项目以获得干净的代码。我想将黄色框从 (fyellow.py) 显示到 (main.py) 并从 (funbut.py 输入标签) 使用Button 的功能。这是我的代码示例:(3 个 Python 文件 - main.py、fyellow.py 和 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()
可以解释如何使用文件 (fyellow.py) 中的 self.framey 来避免
错误'framey' is not defined?
【问题讨论】:
-
好吧....
framey没有定义,你看到有定义的地方吗?使用函数参数将 master 传递给该标签,myframe也不是Frame -
请您安排我的代码,我该怎么做?我非常感谢你的帮助。 @Matiiss
-
请您向我推荐 python Tkinter 的任何在线链接或书籍? (从初学者到专业人士)我在看你管视频..@Matiiss
-
好吧,如果需要,您可以搜索特定库的文档,否则,如果您是初学者,请继续观看 youtube,如果您想了解更多信息,我还建议您练习一下,看看其他人做了什么,如果你问的是什么,也许可以向他们学习
标签: python python-3.x tkinter