请问谁知道下面python代码中,为什么加上Button以后,mainframe不再调用callback了?谢谢。

悠然红茶 2004-04-26 08:18:02
from Tkinter import *

def callback(event):
print "Click : ", event.x, event.y

class App:
def __init__(self, master):
self.root = master;
self.mainframe = Frame(master, width=100, height=150)
self.mainframe.bind('<Button-1>', callback)
self.mainframe.pack()

self.btn1 = Button(self.mainframe, text='hello', command=self.sayHello)
self.btn1.pack(side=LEFT)
return

def sayHello(self):
print str(self.btn1)
print "Hello world!"
return

def StartRun(self):
self.root.mainloop()

root = Tk()
mainApp = App(root)
mainApp.StartRun()
...全文
118 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
悠然红茶 2004-04-29
  • 打赏
  • 举报
回复
噢,我已经知道了,self.mainframe.pack()一句应该写成
self.mainframe.pack(fill=BOTH, expand=1)就可以了。

37,717

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧