英文:
Problem: The scroll bar appears in the parent window, not next to the "Treeview"
问题
这是我的代码,问题是虽然滚动条的包不在树状视图旁边,但滚动条出现在主窗口中,我认为解决方案是一个小细节,但我无法找到,你能帮我吗?
def modulo_dashboard(self):
self.windows_container = Toplevel()
self.windows_container.transient(windows_raiz)
self.windows_container.resizable(width=False, height=False)
self.windows_container.resizable(0,0)
#self.windows_consulta.protocol('WM_DELETE_WINDOW', self.on_exit) # Invalidar x y mandar a función con mensaje
self.windows_container.geometry("1340x530+2+164")
# Medidas del Geometry ("ancho x alto + columna + fila")
# Configuración del Treeview
style = ttk.Style()
style.theme_use("alt") #alt, clam, vista
style.configure("Treeview", background="skyblue2", foreground="black",
rowheight=22, fieldbackground="skyblue2", font=('arial', 11))
style.map("Treeview", background=[('selected', 'navy')], foreground=[('selected', 'white')])
# Agrandar emcabezado
nametofont("TkHeadingFont").configure(size=12)
这里开始Treeview
# Comienza el Treeview
self.tree = ttk.Treeview(self.windows_container, height = 12, columns = ('#0', '#1'), show="headings")
self.tree.place(x=40, y=140)
vsb = ttk.Scrollbar(self.windows_container, orient="vertical", command=self.tree.yview)
vsb.pack(side=RIGHT, fill=BOTH)
self.tree.column("#0", width=0, minwidth=0)
self.tree.column("#1", width=300, minwidth=50)
self.tree.column("#2", width=200, minwidth=50)
self.tree.heading('#0', text='', anchor=CENTER)
self.tree.heading('#1', text='位置', anchor=CENTER)
self.tree.heading('#2', text='设备数量', anchor=CENTER)
self.tree.configure(yscrollcommand=vsb.set)
self.tree.bind("<Button-1>", self.selusandoclik5)
英文:
Here is my code, the problem is that the Scrollbar appears in the main window, although its package is not located next to the treeview, I think the solution is a small detail, but I can't get it, can you help me?
def modulo_dashboard(self):
self.windows_container = Toplevel()
self.windows_container.transient(windows_raiz)
self.windows_container.resizable(width=False, height=False)
self.windows_container.resizable(0,0)
#self.windows_consulta.protocol('WM_DELETE_WINDOW', self.on_exit) # Invalidar x y mandar a función con mensaje
self.windows_container.geometry("1340x530+2+164")
# Medidas del Geometry ("ancho x alto + columna + fila")
# Configuración del Treeview
style = ttk.Style()
style.theme_use("alt") #alt, clam, vista
style.configure("Treeview", background="skyblue2", foreground="black",
rowheight=22, fieldbackground="skyblue2", font = ('arial', 11))
style.map("Treeview", background=[('selected', 'navy')], foreground=[('selected', 'white')])
# Agrandar emcabezado
nametofont("TkHeadingFont").configure(size=12)
Here begins the Treeview
# Comienza el Treeview
self.tree = ttk.Treeview(self.windows_container, height = 12, columns = ('#0', '#1'), show="headings")
self.tree.place(x =40, y = 140)
vsb = ttk.Scrollbar(self.windows_container, orient="vertical", command=self.tree.yview)
vsb.pack(side=RIGHT, fill=BOTH)
self.tree.column("#0", width=0, minwidth=0)
self.tree.column("#1", width=300, minwidth=50)
self.tree.column("#2", width=200, minwidth=50)
self.tree.heading('#0', text = '', anchor = CENTER)
self.tree.heading('#1', text = 'Ubicación', anchor = CENTER)
self.tree.heading('#2', text = 'Cantidad Equipos', anchor = CENTER)
self.tree.configure(yscrollcommand=vsb.set)
self.tree.bind("<Button-1>", self.selusandoclik5)
答案1
得分: 3
...
# 用一个框架来包裹树形视图和滚动条
frame = Frame(self.windows_container)
frame.place(x=40, y=140)
# 开始创建树形视图
self.tree = ttk.Treeview(frame, height=12, columns=('#0', '#1'), show='headings')
self.tree.pack(side=LEFT, fill=BOTH, expand=True)
vsb = ttk.Scrollbar(frame, orient='vertical', command=self.tree.yview)
vsb.pack(side=RIGHT, fill=Y)
...
英文:
If you want to stick the treeview and scrollbar together, better put them in a frame and use .pack()
on them:
...
# frame for the treeview and scrollbar
frame = Frame(self.windows_container)
frame.place(x=40, y=140)
# Comienza el Treeview
self.tree = ttk.Treeview(frame, height = 12, columns = ('#0', '#1'), show="headings")
self.tree.pack(side=LEFT, fill=BOTH, expand=True)
vsb = ttk.Scrollbar(frame, orient="vertical", command=self.tree.yview)
vsb.pack(side=RIGHT, fill=Y)
...
答案2
得分: 1
尝试在Treeview
之前(首先声明它)将Scrollbar
进行pack
操作,*-或者-*更好的方法是使用pack()
的before
参数,像这样:
vsb.pack(side='right', fill='both', before=self.tree)
你可能还想将fill
设置为'y'
,这样它只会在垂直方向上填充。
英文:
Try pack
ing the Scrollbar
before the Treeview
(declare it first) -or- better to use the before
parameter of pack()
like so:
vsb.pack(side='right', fill='both', before=self.tree)
You might also want to set the fill
to 'y'
so it only fills vertically
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论