问题:滚动条出现在父窗口中,而不是在“Treeview”旁边。

huangapple go评论90阅读模式
英文:

Problem: The scroll bar appears in the parent window, not next to the "Treeview"

问题

  1. 这是我的代码问题是虽然滚动条的包不在树状视图旁边但滚动条出现在主窗口中我认为解决方案是一个小细节但我无法找到你能帮我吗
  2. def modulo_dashboard(self):
  3. self.windows_container = Toplevel()
  4. self.windows_container.transient(windows_raiz)
  5. self.windows_container.resizable(width=False, height=False)
  6. self.windows_container.resizable(0,0)
  7. #self.windows_consulta.protocol('WM_DELETE_WINDOW', self.on_exit) # Invalidar x y mandar a función con mensaje
  8. self.windows_container.geometry("1340x530+2+164")
  9. # Medidas del Geometry ("ancho x alto + columna + fila")
  10. # Configuración del Treeview
  11. style = ttk.Style()
  12. style.theme_use("alt") #alt, clam, vista
  13. style.configure("Treeview", background="skyblue2", foreground="black",
  14. rowheight=22, fieldbackground="skyblue2", font=('arial', 11))
  15. style.map("Treeview", background=[('selected', 'navy')], foreground=[('selected', 'white')])
  16. # Agrandar emcabezado
  17. nametofont("TkHeadingFont").configure(size=12)
  18. 这里开始Treeview
  19. # Comienza el Treeview
  20. self.tree = ttk.Treeview(self.windows_container, height = 12, columns = ('#0', '#1'), show="headings")
  21. self.tree.place(x=40, y=140)
  22. vsb = ttk.Scrollbar(self.windows_container, orient="vertical", command=self.tree.yview)
  23. vsb.pack(side=RIGHT, fill=BOTH)
  24. self.tree.column("#0", width=0, minwidth=0)
  25. self.tree.column("#1", width=300, minwidth=50)
  26. self.tree.column("#2", width=200, minwidth=50)
  27. self.tree.heading('#0', text='', anchor=CENTER)
  28. self.tree.heading('#1', text='位置', anchor=CENTER)
  29. self.tree.heading('#2', text='设备数量', anchor=CENTER)
  30. self.tree.configure(yscrollcommand=vsb.set)
  31. 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?

  1. def modulo_dashboard(self):
  2. self.windows_container = Toplevel()
  3. self.windows_container.transient(windows_raiz)
  4. self.windows_container.resizable(width=False, height=False)
  5. self.windows_container.resizable(0,0)
  6. #self.windows_consulta.protocol(&#39;WM_DELETE_WINDOW&#39;, self.on_exit) # Invalidar x y mandar a funci&#243;n con mensaje
  7. self.windows_container.geometry(&quot;1340x530+2+164&quot;)
  8. # Medidas del Geometry (&quot;ancho x alto + columna + fila&quot;)
  9. # Configuraci&#243;n del Treeview
  10. style = ttk.Style()
  11. style.theme_use(&quot;alt&quot;) #alt, clam, vista
  12. style.configure(&quot;Treeview&quot;, background=&quot;skyblue2&quot;, foreground=&quot;black&quot;,
  13. rowheight=22, fieldbackground=&quot;skyblue2&quot;, font = (&#39;arial&#39;, 11))
  14. style.map(&quot;Treeview&quot;, background=[(&#39;selected&#39;, &#39;navy&#39;)], foreground=[(&#39;selected&#39;, &#39;white&#39;)])
  15. # Agrandar emcabezado
  16. nametofont(&quot;TkHeadingFont&quot;).configure(size=12)

Here begins the Treeview

  1. # Comienza el Treeview
  2. self.tree = ttk.Treeview(self.windows_container, height = 12, columns = (&#39;#0&#39;, &#39;#1&#39;), show=&quot;headings&quot;)
  3. self.tree.place(x =40, y = 140)
  4. vsb = ttk.Scrollbar(self.windows_container, orient=&quot;vertical&quot;, command=self.tree.yview)
  5. vsb.pack(side=RIGHT, fill=BOTH)
  6. self.tree.column(&quot;#0&quot;, width=0, minwidth=0)
  7. self.tree.column(&quot;#1&quot;, width=300, minwidth=50)
  8. self.tree.column(&quot;#2&quot;, width=200, minwidth=50)
  9. self.tree.heading(&#39;#0&#39;, text = &#39;&#39;, anchor = CENTER)
  10. self.tree.heading(&#39;#1&#39;, text = &#39;Ubicaci&#243;n&#39;, anchor = CENTER)
  11. self.tree.heading(&#39;#2&#39;, text = &#39;Cantidad Equipos&#39;, anchor = CENTER)
  12. self.tree.configure(yscrollcommand=vsb.set)
  13. self.tree.bind(&quot;&lt;Button-1&gt;&quot;, self.selusandoclik5)

答案1

得分: 3

  1. ...
  2. # 用一个框架来包裹树形视图和滚动条
  3. frame = Frame(self.windows_container)
  4. frame.place(x=40, y=140)
  5. # 开始创建树形视图
  6. self.tree = ttk.Treeview(frame, height=12, columns=('#0', '#1'), show='headings')
  7. self.tree.pack(side=LEFT, fill=BOTH, expand=True)
  8. vsb = ttk.Scrollbar(frame, orient='vertical', command=self.tree.yview)
  9. vsb.pack(side=RIGHT, fill=Y)
  10. ...
英文:

If you want to stick the treeview and scrollbar together, better put them in a frame and use .pack() on them:

  1. ...
  2. # frame for the treeview and scrollbar
  3. frame = Frame(self.windows_container)
  4. frame.place(x=40, y=140)
  5. # Comienza el Treeview
  6. self.tree = ttk.Treeview(frame, height = 12, columns = (&#39;#0&#39;, &#39;#1&#39;), show=&quot;headings&quot;)
  7. self.tree.pack(side=LEFT, fill=BOTH, expand=True)
  8. vsb = ttk.Scrollbar(frame, orient=&quot;vertical&quot;, command=self.tree.yview)
  9. vsb.pack(side=RIGHT, fill=Y)
  10. ...

答案2

得分: 1

尝试在Treeview之前(首先声明它)将Scrollbar进行pack操作,*-或者-*更好的方法是使用pack()before参数,像这样:

  1. vsb.pack(side='right', fill='both', before=self.tree)

你可能还想将fill设置为'y',这样它只会在垂直方向上填充。

英文:

Try packing the Scrollbar before the Treeview (declare it first) -or- better to use the before parameter of pack() like so:

  1. vsb.pack(side=&#39;right&#39;, fill=&#39;both&#39;, before=self.tree)

You might also want to set the fill to &#39;y&#39; so it only fills vertically

huangapple
  • 本文由 发表于 2023年3月10日 00:57:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75687725.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定