1

No me deja poner el scrollbar horizontal y que sea funcional no se si porque tengo más de 20 columnas, pero lo he intentado de varias formas y no me deja, al momento de correrlo se ve así introducir la descripción de la imagen aquí, quisiera saber que podria hacer para que se viera de manera correcta

import tkinter as tk
from tkinter import END, Button, ttk
from tkinter import messagebox
from Productos import*
from conexion import *

class FormularioClientes:
   global root
   root = None

   global name_entry
   name_entry = None

   global ds_entry
   ds_entry = None

   global dp_entry
   dp_entry = None

   global w_entry
   w_entry = None

   global v_entry
   v_entry = None

   global hsc_entry
   hsc_entry = None

   global SNP_PROV_entry
   SNP_PROV_entry = None

   global t_entry
   t_entry = None

   global ip_entry
   ip_entry = None

   global m_entry
   m_entry = None

   global p_entry
   p_entry = None

   global lp_entry
   lp_entry = None

   global ti_entry
   ti_entry = None

   global sp_entry
   sp_entry = None

   global cid_entry
   cid_entry = None

   global df_entry
   df_entry = None

   global UCI_entry
   UCI_entry = None

   global b_entry
   b_entry = None

   global po_entry
   po_entry = None

   global so_entry
   so_entry = None

   global D_entry
   D_entry = None

   global treeFrame
   treeFrame = None

   
   
def Formulario():
     global name_entry
     global ds_entry
     global dp_entry
     global w_entry
     global v_entry
     global hsc_entry
     global SNP_PROV_entry
     global t_entry
     global ip_entry
     global m_entry
     global p_entry
     global lp_entry
     global ti_entry
     global sp_entry
     global cid_entry
     global df_entry
     global UCI_entry
     global b_entry
     global po_entry
     global so_entry
     global D_entry
     global treeFrame



     root = tk.Tk()


     style = ttk.Style(root)
     root.tk.call("source", "forest-light.tcl")
     root.tk.call("source", "forest-dark.tcl")
     root.geometry("1200x540")
     style.theme_use("forest-dark")

     frame = ttk.Frame(root)

     frame.pack()

     widgets_frame = ttk.LabelFrame(frame, text="Insert Row")
     widgets_frame.grid(row=0, column=0, padx=20, pady=10)

     name_entry = ttk.Entry(widgets_frame)
     name_entry.insert(0, "Name")
     name_entry.bind("<FocusIn>", lambda e: name_entry.delete('0', 'end'))
     name_entry.grid(row=0, column=0, padx=5, pady=(0, 5), sticky="ew")

     ds_entry = ttk.Entry(widgets_frame)
     ds_entry.insert(0, "Description Sale")
     ds_entry.bind("<FocusIn>", lambda e: ds_entry.delete('0', 'end'))
     ds_entry.grid(row=1, column=0, padx=5, pady=(0, 5), sticky="ew")

     dp_entry = ttk.Entry(widgets_frame)
     dp_entry.insert(0, "Description Purchase")
     dp_entry.bind("<FocusIn>", lambda e: dp_entry.delete('0', 'end'))
     dp_entry.grid(row=2, column=0, padx=5, pady=(0, 5), sticky="ew")

     w_entry = ttk.Entry(widgets_frame)
     w_entry.insert(0, "Weight")
     w_entry.bind("<FocusIn>", lambda e: w_entry.delete('0', 'end'))
     w_entry.grid(row=3, column=0, padx=5, pady=(0, 5), sticky="ew")

     v_entry = ttk.Entry(widgets_frame)
     v_entry.insert(0, "Volume")
     v_entry.bind("<FocusIn>", lambda e: v_entry.delete('0', 'end'))
     v_entry.grid(row=4, column=0, padx=5, pady=(0, 5), sticky="ew")

     hsc_entry = ttk.Entry(widgets_frame)
     hsc_entry.insert(0, "HS Code")
     hsc_entry.bind("<FocusIn>", lambda e: hsc_entry.delete('0', 'end'))
     hsc_entry.grid(row=5, column=0, padx=5, pady=(0, 5), sticky="ew")

     SNP_PROV_entry = ttk.Entry(widgets_frame)
     SNP_PROV_entry.insert(0, "Studio No° de parte Proovedor")
     SNP_PROV_entry.bind("<FocusIn>", lambda e: SNP_PROV_entry.delete('0', 'end'))
     SNP_PROV_entry.grid(row=6, column=0, padx=5, pady=(0, 5), sticky="ew")

     t_entry = ttk.Entry(widgets_frame)
     t_entry.insert(0, "Type")
     t_entry.bind("<FocusIn>", lambda e: t_entry.delete('0', 'end'))
     t_entry.grid(row=7, column=0, padx=5, pady=(0, 5), sticky="ew")

     ip_entry = ttk.Entry(widgets_frame)
     ip_entry.insert(0, "Invoice Policy")
     ip_entry.bind("<FocusIn>", lambda e: v_entry.delete('0', 'end'))
     ip_entry.grid(row=8, column=0, padx=5, pady=(0, 5), sticky="ew")

     m_entry = ttk.Entry(widgets_frame)
     m_entry.insert(0, "UOM ID")
     m_entry.bind("<FocusIn>", lambda e: m_entry.delete('0', 'end'))
     m_entry.grid(row=9, column=0, padx=5, pady=(0, 5), sticky="ew")

     p_entry = ttk.Entry(widgets_frame)
     p_entry.insert(0, "UOMP ID")
     p_entry.bind("<FocusIn>", lambda e: p_entry.delete('0', 'end'))
     p_entry.grid(row=10, column=0, padx=5, pady=(0, 5), sticky="ew")

     lp_entry = ttk.Entry(widgets_frame)
     lp_entry.insert(0, "List Price")
     lp_entry.bind("<FocusIn>", lambda e: lp_entry.delete('0', 'end'))
     lp_entry.grid(row=11, column=0, padx=5, pady=(0, 5), sticky="ew")

     ti_entry = ttk.Entry(widgets_frame)
     ti_entry.insert(0, "IVA")
     ti_entry.bind("<FocusIn>", lambda e: ti_entry.delete('0', 'end'))
     ti_entry.grid(row=0, column=1, padx=5, pady=(0, 5), sticky="ew")

     sp_entry = ttk.Entry(widgets_frame)
     sp_entry.insert(0, "Standar Price")
     sp_entry.bind("<FocusIn>", lambda e: sp_entry.delete('0', 'end'))
     sp_entry.grid(row=1, column=1, padx=5, pady=(0, 5), sticky="ew")

     cid_entry = ttk.Entry(widgets_frame)
     cid_entry.insert(0, "Category ID")
     cid_entry.bind("<FocusIn>", lambda e: cid_entry.delete('0', 'end'))
     cid_entry.grid(row=2, column=1, padx=5, pady=(0, 5), sticky="ew")

     df_entry = ttk.Entry(widgets_frame)
     df_entry.insert(0, "Default Code")
     df_entry.bind("<FocusIn>", lambda e: df_entry.delete('0', 'end'))
     df_entry.grid(row=3, column=1, padx=5, pady=(0, 5), sticky="ew")

     UCI_entry = ttk.Entry(widgets_frame)
     UCI_entry.insert(0, "UNSPSC Code ID")
     UCI_entry.bind("<FocusIn>", lambda e: UCI_entry.delete('0', 'end'))
     UCI_entry.grid(row=4, column=1, padx=5, pady=(0, 5), sticky="ew")

     b_entry = ttk.Entry(widgets_frame)
     b_entry.insert(0, "Barcode")
     b_entry.bind("<FocusIn>", lambda e: b_entry.delete('0', 'end'))
     b_entry.grid(row=5, column=1, padx=5, pady=(0, 5), sticky="ew")

     po_entry = ttk.Entry(widgets_frame)
     po_entry.insert(0, "Purchase Ok")
     po_entry.bind("<FocusIn>", lambda e: po_entry.delete('0', 'end'))
     po_entry.grid(row=6, column=1, padx=5, pady=(0, 5), sticky="ew")

     so_entry = ttk.Entry(widgets_frame)
     so_entry.insert(0, "Sales Ok" )
     so_entry.bind("<FocusIn>", lambda e: so_entry.delete('0', 'end'))
     so_entry.grid(row=7, column=1, padx=5, pady=(0, 5), sticky="ew")

     D_entry = ttk.Entry(widgets_frame)
     D_entry.insert(0, "Division" )
     D_entry.bind("<FocusIn>", lambda e: D_entry.delete('0', 'end'))
     D_entry.grid(row=8, column=1, padx=5, pady=(0, 5), sticky="ew")

     Button(widgets_frame,text ="Guardar", width=10, command= GuardarRegistros).grid(row=12, column=0)
     Button(widgets_frame,text ="Eliminar", width=10).grid(row=12, column=1)
     Button(widgets_frame,text ="Modificar", width=10).grid(row=13, column=0)
     Button(widgets_frame,text ="Buscar", width=10).grid(row=13, column=1)
     separator = ttk.Separator(widgets_frame)
     separator.grid(row=9, column=1, padx=(20, 10), pady=10, sticky="ew")
     treeFrame = ttk.Frame(frame)
     treeFrame.grid(row=0, column=3, pady=10,)

Aqui intente poner los scrollbar pero como se que python funciona con espaciados no se si es ese mi problema

     hscrollbar = ttk.Scrollbar(orient=tk.HORIZONTAL)
     hscrollbar.place(x=530, y=1200, width=200)
     hscrollbar.set("0.5", "0.6")
     
     vscrollbar = ttk.Scrollbar(orient=tk.VERTICAL)
     vscrollbar.place(x=50, y=50, height=200)
     vscrollbar.set("0.0", "0.1")
     cols = ("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23")
     treeview = ttk.Treeview(treeFrame, show="headings",
                        columns=cols, height=20)
    

     treeview.column("01", width=20)
     treeview.heading("01",text="ID",)
     treeview.column("02", width=90)
     treeview.heading("02", text="Name")
     treeview.column("03", width=190)
     treeview.heading("03", text="Description Purchase")
     treeview.column("04", width=10)
     treeview.heading("04", text="Description Sale")
     treeview.column("05", width=100)
     treeview.heading("05", text="Weight")
     treeview.column("06", width=100)
     treeview.heading("06", text="Volume")
     treeview.column("07", width=100)
     treeview.heading("07", text="HS Code")
     treeview.column("08", width=100)
     treeview.heading("08", text="Studio No° de parte Proovedor")
     treeview.column("09", width=100)
     treeview.heading("09", text="Type")
     treeview.column("10", width=100)
     treeview.heading("10", text="Invoice Policy")
     treeview.column("11", width=100)
     treeview.heading("11", text="UOM ID")
     treeview.column("12", width=100)
     treeview.heading("12", text="UOMP ID")
     treeview.column("13", width=100)
     treeview.heading("13", text="List Price")
     treeview.column("14", width=100)
     treeview.heading("14", text="IVA")
     treeview.column("15", width=100)
     treeview.heading("15", text="Standar Price")
     treeview.column("16", width=100)
     treeview.heading("16", text="Category ID")
     treeview.column("17", width=100)
     treeview.heading("17", text="Default Code")
     treeview.column("18", width=100)
     treeview.heading("18", text="UNSPSC Code ID")
     treeview.column("19", width=100)
     treeview.heading("19", text="Barcode")
     treeview.column("20", width=100)
     treeview.heading("20", text="Purchase Ok")
     treeview.column("21", width=100)
     treeview.heading("21", text="Purchase Ok")
     treeview.column("22", width=100)
     treeview.heading("22", text="Sales Ok")
     treeview.column("23", width=100)
     treeview.heading("23", text="Division")

     treeview.pack()
     
    
     #Agregar datos a la Tabla
     #Mostrar la tabla 
     for row in PProductos.MostrarProductos():
        treeview.insert("","end",values=row)

     root.mainloop()

def GuardarRegistros():
 
 global name_entry,ds_entry,dp_entry,w_entry,v_entry,hsc_entry,SNP_PROV_entry,t_entry,ip_entry,m_entry,p_entry,lp_entry,ti_entry,sp_entry,cid_entry,df_entry,UCI_entry,b_entry,po_entry,so_entry,D_entry,treeFrame
 entry = ("name_entry,ds_entry,dp_entry,w_entry,v_entry,hsc_entry,SNP_PROV_entry,t_entry,ip_entry,m_entry,p_entry,lp_entry,ti_entry,sp_entry,cid_entry,df_entry,UCI_entry,b_entry,po_entry,so_entry,D_entry,treeFrame")

 try:
  #Verificar si los widgets esten inicialisados 
     if entry is None:
         print("Los widgets no estan inicializados")
         return
     Nombres = name_entry.get()
     Description_Purchase = dp_entry.get()
     description_Sale = ds_entry.get()
     Peso= w_entry.get()
     Volumen =v_entry.get()
     Codigo_HSC = hsc_entry.get()
     No_Parte_Proov=SNP_PROV_entry.get()
     tipo= t_entry.get()
     InvoiceP = ip_entry.get()
     Medidas=m_entry.get()
     Medidas_USA=p_entry.get()
     lisp_Price=lp_entry.get()
     IVA=ti_entry.get()
     Standar_Price=sp_entry.get()
     Category=cid_entry.get()
     DefaultCode=df_entry.get()
     UnsCodeID=UCI_entry.get()
     barcode=b_entry.get()
     purchaseok=po_entry.get()
     salesok=so_entry.get()
     Division=D_entry.get()
     PProductos.ingresarProductos(Nombres,Description_Purchase,description_Sale, 
                                Peso,Volumen,Codigo_HSC,No_Parte_Proov,tipo,
                                InvoiceP,Medidas,Medidas_USA,lisp_Price,IVA,
                                Standar_Price,Category,DefaultCode,UnsCodeID,
                                barcode,purchaseok,salesok,Division)
     messagebox.showinfo("Informacion","Los datos fueron Guardados")
     #Limpiar los campos
     name_entry.delete(0,END)
     dp_entry.delete(0,END)
     ds_entry.delete(0,END)
     w_entry.delete(0,END)
     v_entry.delete(0,END)
     hsc_entry.delete(0,END)
     SNP_PROV_entry.delete(0,END)
     t_entry.delete(0,END)
     ip_entry.delete(0,END)
     m_entry.delete(0,END)
     p_entry.delete(0,END)
     lp_entry.delete(0,END)
     ti_entry.delete(0,END)
     sp_entry.delete(0,END)
     cid_entry.delete(0,END)
     df_entry.delete(0,END)
     UCI_entry.delete(0,END)
     b_entry.delete(0,END)
     po_entry.delete(0,END)
     so_entry.delete(0,END)
     D_entry.delete(0,END)
 except ValueError as error:
    print("Error al ingresar los datos{}".format(error))

Formulario()

Ya he intentado de todo tipo de cosas pero simplemente no puedo hacer que funcione ya sea horizontal o vertical no se si se me esta olvidando algo ocomo habia dicho el tamaño de las columnas

1 respuesta 1

0

Varias cosas a tener en cuenta:

  • Si tus scrollbars son solo para el treeview, lo más lógico es posicionarlas dentro del mismo frame que éste. Ahora mismo estas usando place para posicionarlas en la ventana principal.

  • Debes forzar al treeview a restringir su anchura (y eventualmente su altura), en caso contrario se expandirá fuera de los limites de la pantalla y la scroollbar será inútil. Esto se puede conseguir asignando un peso a la columna del frame que ocupa el treeview y a su frame contenedor.

  • Tienes que asociar la scrollbar al treeview y viceversa para que al desplazar uno el otro responda de forma acorde.

El código relevante a modificar es el siguiente:

# ...
# separator.grid(row=9, column=1, padx=(20, 10), pady=10, sticky="ew")

tree_frame = ttk.Frame(frame)
frame.rowconfigure(0, weight=1)
frame.columnconfigure(3, weight=1)
tree_frame.rowconfigure(0, weight=1)
tree_frame.columnconfigure(0, weight=1)
tree_frame.grid(row=0, column=3, pady=22, sticky="ns")
 
cols = tuple(f"{n:0>2}" for n in range(1, 24))
treeview = ttk.Treeview(
    tree_frame, show="headings", columns=cols, height=20
)
treeview.grid(row=0, column=0, sticky='ns')
 
vscrollbar = ttk.Scrollbar(
    tree_frame, orient="vertical", command=treeview.yview
)
treeview.configure(yscrollcommand=vscrollbar.set)
vscrollbar.grid(row=0, column=1, sticky='ns')

hscrollbar = ttk.Scrollbar(
    tree_frame, orient="horizontal", command=treeview.xview
)
treeview.configure(xscrollcommand=hscrollbar.set)
hscrollbar.grid(row=1, column=0, sticky='ew')

# treeview.column("01", width=20)
# ...

introducir la descripción de la imagen aquí

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.