【发布时间】:2017-03-01 01:16:32
【问题描述】:
目前这是我的代码:
from tkinter import *
class Application(Frame):
def a(self, event = None):
print ("a")
def create_widgets(self):
def b(event = None):
print(entry.get())
entry = Entry()
entry.grid(row = 1, column = 1)
Button(text = "b", command = b).grid(row = 1, column = 2)
def __init__(self, master = None):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
master.bind("<Return>", b)
root = Tk()
app = Application(master = root)
app.mainloop()
到目前为止,它调用了 a,但是将 self.a 替换为 self.b 以使其调用 b 会引发 AttributeError: 'Application' object has no attribute 'b' and with just b returns a NameError: 'b' is未定义。
那么我怎样才能像按钮一样进行绑定调用?
【问题讨论】:
标签: python-3.x tkinter