gpt4 book ai didi

python - 滚动条滚动文本小部件,使用网格布局,在 Tkinter

转载 作者:太空狗 更新时间:2023-10-30 00:27:50 28 4
gpt4 key购买 nike

我正在尝试使用 Tkinter 中的网格布局管理器来创建对话框。我希望底部的文本区域有一个滚动条。不幸的是,我无法弄清楚如何使滚动条与其旁边的文本小部件的高度相同。下面的示例显示滚动条在正确的位置,但大小不正确(只有文本小部件高度的大约 10%)。

layout issue with tkinter grid and scrollbar

from tkinter import *

class queryrunner(Tk):
def __init__(self,parent):
Tk.__init__(self,parent)
self.parent = parent
self.minsize(width=800,height=500)
self.initialize()

def initialize(self):
self.grid_columnconfigure(2,weight=1)
self.grid_columnconfigure(3,weight=1)
self.grid_columnconfigure(6,weight=2)
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)
# BUCKET AND N1QL LABEL + INPUT PAIRS:
self.label = Label(self,text="Bucket", width=10, anchor="w")
self.label.grid(column=0,row=0,columnspan=1,sticky='W')
self.entry = Entry(self);
self.entry.grid(column=1,row=0, columnspan=3, sticky='EW')
self.entry.insert(0, "couchbase://couchbase1.mycompany.com/beer-sample" )
# EXECUTE N1QL QUERY AGAINST BUCKET WHEN BUTTON CLICKED:
self.button = Button(self,text="Go",width=20)
self.button.grid(column=6,row=0)
self.label2 = Label(self,text="N1QL", anchor="w")
self.label2.grid(column=0,row=1,columnspan=1,sticky='W')
self.entry2 = Text(self,height=5);
self.entry2.grid(column=1,row=1, columnspan=3, rowspan=1, sticky='W')

self.label3 = Label(self,text="Output:", width=50,anchor="w")
self.label3.grid(column=0,row=4,columnspan=5,sticky='W')
self.entry3 = Text(self,height=18)
self.entry3.grid(column=1,row=5, columnspan=5, rowspan=1, sticky='W')
# PROBLEM: GET SCROLLBAR TO BE THE RIGHT SIZE (IT'S NOT THE SIZE OF THE THING ITS BESIDE)
self.scrollbar = Scrollbar(self) # height= not permitted here!
self.entry3.config(yscrollcommand= self.scrollbar.set)
self.scrollbar.config(command= self.entry3.yview)
self.grid()
self.scrollbar.grid(column=6, row=5, rowspan=2, sticky='W')


if __name__ == "__main__":
app = queryrunner(None)
#font.nametofont('TkDefaultFont').configure(size = 10 )
app.title('Couchbase N1QL Query Runner')
app.mainloop()

最佳答案

在Scrollbar网格调用的sticky选项中添加North和South,使Scrollbar在垂直方向上被拉伸(stretch)。

self.scrollbar.grid(column=6, row=5, rowspan=2,  sticky=N+S+W)

关于python - 滚动条滚动文本小部件,使用网格布局,在 Tkinter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30517089/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com