python调试问题
from tkinter import *
from tkinter.messagebox import *
class app:
def __init__(self):
self.lb = Label(text='Hello World !', fg='red')
self.lb.pack()
self.scc = Scale(from_=10,to=40,orient=HORIZONTAL)
self.scc.set(40)
self.scc.pack(fill=X, expand=1)
self.scc.bind('<Button-1>',self.resize())
def resize(self):
self.lb.config(text='%d' % self.scc.get())
showinfo('ss')
if __name__ == "__main__":
root = Tk()
root.minsize(600,600)
roots = app()
root.mainloop()
为什么每次运行都会自动执行按钮的点击(也就是resize会自动执行,根本不用手动去点击),之后再手动点击按钮就没有反映了,请高手帮忙
[解决办法]
from tkinter import *from tkinter.messagebox import *class app: def __init__(self): self.lb = Label(text='Hello World !', fg='red') self.lb.pack() self.scc = Scale(from_=10,to=40,orient=HORIZONTAL,command=self.resize) self.scc.set(40) self.scc.pack(fill=X, expand=1) #self.scc.bind('<Button-1>',self.resize()) def resize(self, value): self.lb.config(text='%d' % self.scc.get()) print(value)if __name__ == "__main__": root = Tk() root.minsize(600,600) roots = app() root.mainloop()