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

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

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(&#39;WM_DELETE_WINDOW&#39;, self.on_exit) # Invalidar x y    mandar a funci&#243;n con mensaje 
self.windows_container.geometry(&quot;1340x530+2+164&quot;)
#   Medidas del Geometry (&quot;ancho x alto + columna + fila&quot;)
#   Configuraci&#243;n del Treeview
style = ttk.Style()
style.theme_use(&quot;alt&quot;) #alt, clam, vista
style.configure(&quot;Treeview&quot;, background=&quot;skyblue2&quot;, foreground=&quot;black&quot;,
rowheight=22, fieldbackground=&quot;skyblue2&quot;, font = (&#39;arial&#39;, 11))
style.map(&quot;Treeview&quot;, background=[(&#39;selected&#39;, &#39;navy&#39;)], foreground=[(&#39;selected&#39;, &#39;white&#39;)])
#   Agrandar emcabezado
nametofont(&quot;TkHeadingFont&quot;).configure(size=12)

Here begins the Treeview

# Comienza el Treeview
self.tree = ttk.Treeview(self.windows_container, height = 12, columns = (&#39;#0&#39;, &#39;#1&#39;), show=&quot;headings&quot;)
self.tree.place(x =40, y = 140)
vsb = ttk.Scrollbar(self.windows_container, orient=&quot;vertical&quot;, command=self.tree.yview)
vsb.pack(side=RIGHT, fill=BOTH)
self.tree.column(&quot;#0&quot;, width=0, minwidth=0)
self.tree.column(&quot;#1&quot;, width=300, minwidth=50)
self.tree.column(&quot;#2&quot;, width=200, minwidth=50)
self.tree.heading(&#39;#0&#39;, text = &#39;&#39;, anchor = CENTER)
self.tree.heading(&#39;#1&#39;, text = &#39;Ubicaci&#243;n&#39;, anchor = CENTER)
self.tree.heading(&#39;#2&#39;, text = &#39;Cantidad Equipos&#39;, anchor = CENTER)
self.tree.configure(yscrollcommand=vsb.set)
self.tree.bind(&quot;&lt;Button-1&gt;&quot;, 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 = (&#39;#0&#39;, &#39;#1&#39;), show=&quot;headings&quot;)
self.tree.pack(side=LEFT, fill=BOTH, expand=True)

vsb = ttk.Scrollbar(frame, orient=&quot;vertical&quot;, 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 packing the Scrollbar before the Treeview (declare it first) -or- better to use the before parameter of pack() like so:

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:

确定