Tkinter/Python - 在窗口调整大小时禁用调整按钮的大小
问题描述:
我有一个窗口,它带有一个可以相互调整大小的列表框。我正在使用网格。列表框下方有一排按钮,当前正在移动窗口并调整窗口大小。我希望按钮保持原状并保持一致的大小,同时窗口和列表框的大小调整(所以按钮始终保留在列表框的左下角)。Tkinter/Python - 在窗口调整大小时禁用调整按钮的大小
有没有简单的方法来做到这一点?我刚刚开始使用Tkinter,因此我可能只是在文档中错过了它,或者可能只是在网格布局上感到困惑。
按钮被设置如下:
nextbutton = Button(self, width = 30, height = 30, image = ffbtn)
nextbutton.image = ffbtn
nextbutton.bind("<Button-1>", self.forward)
nextbutton.grid(row = 10, column=4, sticky='w')
我已经尝试了所有粘组合,但不调整按钮还是让他们走动,这是我不希望的。
编辑:这是一个非常基本的例子,我正在谈论,要求。当窗口调整大小时,按钮会彼此分离。我不想那样。
在旁注中,即使我使用列或行占据所有空间的列/行,我是否还需要所有网格配置来设置重量?
import tkinter
from tkinter import *
from tkinter import ttk
class Application(tkinter.Tk):
def __init__(self, parent):
tkinter.Tk.__init__(self, parent)
self.minsize(300,300)
self.parent = parent
self.main()
def main(self):
self.grid()
listbox = tkinter.Listbox(self, width=20, height=25, bg = 'grey')
listbox.grid(padx=30, pady=30, columnspan=11, sticky='NEW')
bt1 = Button(self, width = 5, height = 5)
bt1.grid(row=10, column=0, padx=(30,0), sticky='w')
bt2 = Button(self, width = 5, height = 5)
bt2.grid(row = 10, column=1, sticky='w')
bt3 = Button(self, width = 5, height = 5)
bt3.grid(row = 10, column=2, sticky='w')
bt4 = Button(self, width = 5, height = 5)
bt4.grid(row = 10, column=3, sticky='w')
bt5 = Button(self, width = 5, height = 5)
bt5.grid(row = 10, column=4, sticky='w')
self.grid_columnconfigure(0,weight=1)
self.grid_columnconfigure(1,weight=1)
self.grid_columnconfigure(2,weight=1)
self.grid_columnconfigure(3,weight=1)
self.grid_columnconfigure(4,weight=1)
self.grid_columnconfigure(5,weight=1)
self.grid_columnconfigure(6,weight=1)
self.grid_columnconfigure(7,weight=1)
self.grid_columnconfigure(8,weight=1)
self.grid_columnconfigure(9,weight=1)
self.grid_columnconfigure(10,weight=1)
self.grid_rowconfigure(0,weight=1)
self.grid_rowconfigure(1,weight=1)
self.grid_rowconfigure(2,weight=1)
self.grid_rowconfigure(3,weight=1)
self.grid_rowconfigure(4,weight=1)
self.grid_rowconfigure(5,weight=1)
self.grid_rowconfigure(6,weight=1)
self.grid_rowconfigure(7,weight=1)
self.grid_rowconfigure(8,weight=1)
self.grid_rowconfigure(9,weight=1)
self.grid_rowconfigure(10,weight=1)
app = Application(None)
app.mainloop()
请创建一个[mcve] –
^只需将其添加到原始文章 – mxvx