Tkinter Custom Widget rowconfigure缺少参数'index'(Tkinter Custom Widget rowconfigure missing a

系统教程 行业动态 更新时间:2024-06-14 16:57:17
Tkinter Custom Widget rowconfigure缺少参数'index'(Tkinter Custom Widget rowconfigure missing argument 'index')

我写了一个包含Label,Entry和Treeview的自定义小部件。 现在我想要那个自定义小部件来填充我想要放置的框架。我认为rowconfigure是要做的事情。 所以我的代码如下所示:

import tkinter as tk import tkinter.ttk as ttk class CustomWidget(tk.Frame): def __init__(self, parent): tk.Frame.__init__(self, parent) tk.Frame.rowconfigure(3, weight=1) self.Search_Text_Label = tk.Label(self, text="Search:",font=("Century Gothic",12)) self.Search_Text_Label.grid(row=1,column=1, sticky='W', padx=10) self.entry = tk.Entry(self, width=30) self.entry.grid(row=1,column=2, sticky='W') self.entry.bind('<Return>',search) self.tree = ttk.Treeview(self) self.tree.state = "disabled" self.tree.grid(row=2,column=1,columnspan=2, rowspan=2, sticky='S', pady=0, padx=20)

但是我得到这个错误信息:

TypeError:grid_rowconfigure()缺少1个需要的位置参数:'index'

我需要改变什么? 这真的是要走的路吗?

I wrote a custom widget which contains a Label, Entry and a Treeview. Now I want that custom widget to fill the frame I would like to place it in. I thought rowconfigure was the thing to go. So my code looks like this:

import tkinter as tk import tkinter.ttk as ttk class CustomWidget(tk.Frame): def __init__(self, parent): tk.Frame.__init__(self, parent) tk.Frame.rowconfigure(3, weight=1) self.Search_Text_Label = tk.Label(self, text="Search:",font=("Century Gothic",12)) self.Search_Text_Label.grid(row=1,column=1, sticky='W', padx=10) self.entry = tk.Entry(self, width=30) self.entry.grid(row=1,column=2, sticky='W') self.entry.bind('<Return>',search) self.tree = ttk.Treeview(self) self.tree.state = "disabled" self.tree.grid(row=2,column=1,columnspan=2, rowspan=2, sticky='S', pady=0, padx=20)

But I get this error message:

TypeError: grid_rowconfigure() missing 1 required positional argument: 'index'

What do I have to change? And is this really the way to go?

最满意答案

你在类tk.Frame上调用tk.Frame 。 相反,你应该在自己的类实例上调用它,所以:

self.rowconfigure(3, weight=1)

另外,如果你想Treeview垂直拉伸,你应该使用sticky='NS' 。

You're calling rowconfigure on the class tk.Frame. Instead, you should call it on your class instance, which is self, so:

self.rowconfigure(3, weight=1)

Also, if you want the Treeview to stretch vertically, you should use sticky='NS'.

更多推荐

本文发布于:2023-04-12 20:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/e9983dfee4ac516f1c058b992aefb277.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   Widget   Tkinter   Custom   rowconfigure

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!