类中的Tkinter回调 [英] Tkinter callback in a class
本文介绍了类中的Tkinter回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我理解概念回调按钮在函数和过程。如何应用这个代码在类?我有问题关于回调按钮在Tkinter从类中获取值我无法访问回调方法。恐怖程序=回调没有定义。
来自Tkinter import *
类程序:
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
。
code> printhello
I understand concept callback button in function and procedure.How to apply this code in class?I have problem about callback button in Tkinter for get value from class.I can't access callback method.Eror program = callback not define.
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()
解决方案What you need to do is use:
command=self.callback
instead ofcommand=callback
.Also, it should be
print "hello"
这篇关于类中的Tkinter回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文