Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tkinter柱配置重量不调整_Python_Python 3.x_Tkinter_Tkinter Layout - Fatal编程技术网

Python Tkinter柱配置重量不调整

Python Tkinter柱配置重量不调整,python,python-3.x,tkinter,tkinter-layout,Python,Python 3.x,Tkinter,Tkinter Layout,我是Tkinter模块的新手。我只有PyQt5的经验。我正在我的框架中玩一些小部件。它们是三个按钮,我正在尝试相对于窗口的大小扩展它们的大小。为此,我使用w.columnconfigure(n,weight=1)。这应该将我的3个按钮分布在整个窗框上。这是我正在运行的代码。在将小部件放入网格之前,以及在将小部件放入网格之后(如发布的代码所示),我已经尝试了w.columnconfigure。我没有注意到任何差异或功能。有会议吗?无论如何,感谢您的指导 def create_widgets

我是Tkinter模块的新手。我只有PyQt5的经验。我正在我的框架中玩一些小部件。它们是三个按钮,我正在尝试相对于窗口的大小扩展它们的大小。为此,我使用w.columnconfigure(n,weight=1)。这应该将我的3个按钮分布在整个窗框上。这是我正在运行的代码。在将小部件放入网格之前,以及在将小部件放入网格之后(如发布的代码所示),我已经尝试了w.columnconfigure。我没有注意到任何差异或功能。有会议吗?无论如何,感谢您的指导

    def create_widgets(self):
        """ Create three buttons that do nothing. """
        self.bttn1 = Button(self, text="I do nothing")

        self.bttn2 = Button(self)
        self.bttn2.configure(text="Me too!")   

        self.bttn3 = Button(self)
        self.bttn3["text"] = "Same here!"

        self.bttnCt = Button(self)
        self.bttnCt["text"] = "Total Clicks: 0"
        self.bttnCt["command"] = self.update_count

        self.bttn1.grid(row=0, column=0, sticky=W+E)
        self.bttn2.grid(row=0, column=1, sticky=W+E)
        self.bttn3.grid(row=0, column=2, sticky=W+E)
        self.bttnCt.grid(row=1, column=1, sticky=W+E)

        bttn_list = [self.bttn1, self.bttn2, self.bttn3, self.bttnCt]

        for k, i in enumerate(bttn_list):
            i.columnconfigure(k, weight=1)

        #self.bttn1.columnconfigure(0, weight=1)
        #self.bttn2.columnconfigure(1, weight=3)        
        #self.bttn3.columnconfigure(2, weight=1)
        #self.bttnCt.columnconfigure(3, weight=1) 
columnconfigure()
rowconfigure()
函数应用于窗口或框架,小部件是其中的一部分。在这里,您将其应用于按钮本身。基本上,将其应用于其父项上

这里有一个小例子

import tkinter as tk

app = tk.Tk()

bttn1 = tk.Button(app, text="I do nothing")
bttn2 = tk.Button(app, text='Me too!')
bttn3 = tk.Button(app, text='Same here!')
bttnCt = tk.Button(app, text='Total Clicks: 0')

bttn1.grid(row=0, column=0, sticky="ew")
bttn2.grid(row=0, column=1, sticky="ew")
bttn3.grid(row=0, column=2, sticky="ew")
bttnCt.grid(row=1, column=1, sticky="ew")

bttn_list = [bttn1, bttn2, bttn3, bttnCt]

for i in range(len(bttn_list)):
    app.columnconfigure(i, weight=1) ## Not the button, but the parent

app.mainloop()

谢谢。我相信你的回答是对的。然而,我仍然停留在语义上。我在类内部创建按钮、列。根窗口在应用程序类外部创建。Root或“app”窗口充当我的应用程序类的主窗口<代码>类应用程序(框架):…
root=Tk()root.title(“…扩展GUI…”)root.geometry(“500x650”)app=Application(root)root.mainloop()
luck@thebtcfuture您尚未提供完整的代码。所以我不知道你的应用程序是如何工作的。但概念仍然是一样的。请尝试给我们完整的代码,删除不必要的部分。@在您的代码中,
self
是按钮的父级,因此
self.columnconfigure(…)
应该可以工作。但是,这对
应用程序
框架
放置在
根目录中的方式没有任何影响。。如果你在这方面需要更多的帮助,你应该发布一篇文章,其中包括所有要运行的内容,并查看你的问题。