Class 类中的Tkinter回调
我理解函数和过程中回调按钮的概念。如何在类中应用此代码?我对Tkinter中用于从类中获取值的回调按钮有问题。我无法访问回调方法。Eror program=回调未定义Class 类中的Tkinter回调,class,python-2.7,tkinter,Class,Python 2.7,Tkinter,我理解函数和过程中回调按钮的概念。如何在类中应用此代码?我对Tkinter中用于从类中获取值的回调按钮有问题。我无法访问回调方法。Eror program=回调未定义 from Tkinter import * class Program: def __init__(self): self.root = Tk() self.root.title("Sample") self.display = Entry(self.root)
from Tkinter import *
class Program:
def __init__(self):
self.root = Tk()
self.root.title("Sample")
self.display = Entry(self.root)
self.display.grid(row=1, column=0, columnspan=5)
Button(self.root, text="Proces", width=5, foreground="blue", command=callback).grid(row=4, column=0)
def callback(self):
print hello
program = Program()
mainloop()
您需要做的是使用:
command=self.callback
而不是command=callback
另外,它应该是打印“hello”您需要做的是使用:
command=self.callback
而不是command=callback
另外,它应该是打印“hello”您需要做的是使用:
command=self.callback
而不是command=callback
另外,它应该是打印“hello”您需要做的是使用:
command=self.callback
而不是command=callback
此外,如果您觉得我的答案信息丰富且有帮助,请打印“hello”,谢谢。这是告诉人们你已经找到答案的一种方式。没有义务,但是:)如果你觉得我的答案信息丰富,有帮助,请回答。这是告诉人们你已经找到答案的一种方式。没有义务,但是:)如果你觉得我的答案信息丰富,有帮助,请回答。这是告诉人们你已经找到答案的一种方式。没有义务,但是:)如果你觉得我的答案信息丰富,有帮助,请回答。这是告诉人们你已经找到答案的一种方式。但是,没有义务:)