为了账号安全,请及时绑定邮箱和手机立即绑定

从具有继承的类调用函数

从具有继承的类调用函数

FFIVE 2022-12-14 20:34:25
我确定我在类/继承理解方面遗漏了一些东西。当我点击提交按钮时,出现此错误:我尝试了很多变体,比如改变按钮中的命令、改变主人、定义 self.controller。我怎样才能使提交按钮工作?这是主窗口的图片,因此您也会得到一个视觉概念。 
查看完整描述

1 回答

?
猛跑小猪

TA贡献1858条经验 获得超8个赞

我认为错误出在testPing课堂上;特别是在这些方面:


class testPing(tk.Frame):

...

        clearFileRadioYes = tk.Radiobutton(self, text="yes", value=True, var=clearFile,

                                           command=lambda: testPing.callback(clearFile.get()))

        clearFileRadioYes.pack(anchor="w")

        clearFileRadioNo = tk.Radiobutton(self, text="no", value=False, var=clearFile,

                                          command=lambda: testPing.callback((clearFile.get())))

        clearFileRadioNo.pack(anchor="w")


        urlSubmitButton = tk.Button(self, text="Submit",

                                    command=lambda: testPing.pingURL(urlInputBox.get(),

                                                     testPing(clearFile.get())))

你在里面testPing,所以你应该使用self而不是testPing显式使用。所以,你的代码应该是:


class testPing(tk.Frame):

...

        clearFileRadioYes = tk.Radiobutton(self, text="yes", value=True, var=clearFile,

                                           command=lambda: self.callback(clearFile.get()))

        clearFileRadioYes.pack(anchor="w")

        clearFileRadioNo = tk.Radiobutton(self, text="no", value=False, var=clearFile,

                                          command=lambda: self.callback((clearFile.get())))

        clearFileRadioNo.pack(anchor="w")


        urlSubmitButton = tk.Button(self, text="Submit",

                                    command=lambda: self.pingURL(urlInputBox.get(),

                                                     clearFile.get()))

注意使用self而不是testPing


查看完整回答
反对 回复 2022-12-14
  • 1 回答
  • 0 关注
  • 50 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信