【发布时间】:2018-05-06 11:32:22
【问题描述】:
我有一个按钮,点击后会显示滑块/比例。如何从滑块中获取选定的值? 我的代码返回错误:“TypeError: funcSlider() missing 1 required positional argument: 'value'”
self.list = {}
def onClick(self):
print (self.list)
return
def funcSlider(self, posX,posY,key,value):
w = tk.Scale(self, from_=0, to=8, orient='horizontal')
w.pack()
w.place(x=posX, y=posY, in_=self)
self.list [key] = value
button = tk.Button(self, text="button ",
command=lambda: self.funcSlider(120,33,'test'),width = 20)
button .pack(anchor="w")
button .place(x=250, y=50, in_=self)
button2 = tk.Button(self, text="Send",
command=self.onClick, width=42,bg="#4BAD2E")
button2 .pack(anchor="w")
button2 .place(x=250, y=430, in_=self)
【问题讨论】:
-
函数
funcSlider()的代码在哪里?似乎需要 4 个参数,你给了它 3 个 -
@Begueradj 对不起,我打错了:(我已经更正了代码
-
注意:如果您稍后致电
w.place(),则无需致电w.pack()。对于任何给定的小部件,您只能使用一个几何管理器,并且您使用的最后一个是具有任何效果的那个。
标签: python-3.x tkinter