我想构建用于观察结果的GUI。但是,由于GUI包含多个模块,每个模块都包含多个小部件,我还想在将来添加额外的函数,所以我为每个模块构造了多个python脚本。主模块(称为test.py)如下所示:
import tkinter as Tk
from tkinter import*
import test2
class test:
def __init__(self,master):
button = Button(gui, text = 'click here', command = self.printtestcommand)
button.pack()
gui = Tk()
a = test(gui)
gui.mainloop()
命令printtestcommand位于另一个脚本(test2.py)上:
def printtestcommand(self):
print('Test completed')
但是当我运行test.py脚本时,遇到了以下错误:
AttributeError: 'test' object has no attribute 'printtestcommand'
有人能告诉我我哪里出了问题,以及如何解决这个问题吗
目前没有回答
相关问题 更多 >
编程相关推荐