from Tkinter import *
import decoding
import encoding
import zxc
version="v0.0"
class widgets():
def NewLabel(self, text, column, row, container):
self.label=Label(container, text=text)
self.label.grid(column=column,row=row)
def NewEntry(self, container, text, column, row, action, key='<Return>', sticky="EW"):
self.entry=Entry(container, textvariable=StringVar())
self.entry.grid(column=column, row=row, sticky=sticky)
self.entry.bind(key, action)
StringVar().set(text)
def NewButton(self, text, action, column, row, container, sticky="N"):
self.button=Button(container, text=text, command=action)
self.button.grid(column=column,row=row,sticky=sticky)
class actions():
def OnEncode(self):
try:
zxc.encode()
quit()
except KeyboardInterrupt:
print "goodbye"
quit()
def OnDecode(self):
try:
decoding.decode(version)
except KeyboardInterrupt:
print "Goodbye"
quit()
def OnExit(self):
print __name__
if __name__=="zxc":
quit()
按钮包括:
widgets().NewButton(u'Exit',actions().OnExit(),0,4,self)
现在正在运行,程序打印出我的'定义'和窗口,弹出不可点击的按钮
答案 0 :(得分:0)
执行此操作时:
widgets().NewButton(..., actions().OnExit(), ...)
...然后你明确地调用OnExit()
方法返回任何actions()
。然后将结果传递给按钮。
相反,您需要传递对函数的引用,而不是直接调用函数。简而言之,删除尾部括号:
widgets().NewButton(..., actions().OnExit, ...)