[英]Using Tkinter set() attribute with grid layout in python
I've tried a number of different ways to use the Slider set()
in tkinter with the grid layout and I cannot get it to recognize the attribute. 我尝试了多种不同的方法在tkinter中使用Slider
set()
与网格布局,但无法识别该属性。
Here's a functional version not using set(): 这是不使用set()的功能版本:
master = Tk()
master.title("This is a title")
Scale(master, from_=0, to=100, label='Brightness').grid(row=0, sticky=W)
master.mainloop()
This works as would be expected. 这将按预期工作。 But if I change to:
但是,如果我更改为:
Scale(master, from_=0, to=100, label='Brightness').set(50).grid(row=0, sticky=W)
I receive: AttributeError: 'NoneType' object has no attribute 'grid'
我收到:
AttributeError: 'NoneType' object has no attribute 'grid'
If I try to assign the scale to a variable with set()
and then use that variable with .grid(row=0, sticky=W)
I receive the same thing. 如果我尝试通过
set()
将比例分配给变量,然后将其与.grid(row=0, sticky=W)
一起使用, .grid(row=0, sticky=W)
收到相同的结果。
What is it that I am missing here? 我在这里想念什么? I looked through the docs, but it seems there's little on
grid()
as compared to pack()
. 我浏览了一下文档,但与
pack()
相比, grid()
似乎很少。
This should work. 这应该工作。
scl = Scale(master, from_=0, to=100, label='Brightness')
scl.set(50)
scl.grid(row=0, sticky=W)
set method returns None. set方法返回None。 You are getting None type error because of that.
因此,您将收到None类型错误。 As you can see from above code, you should first assign to a variable then use methods on that variable.
从上面的代码可以看到,您应该首先分配一个变量,然后对该变量使用方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.