0

I've a little program that pop ups a window and shows some text that are saved on an array:

enter image description here

What I want to do is add a scroll at the right side of the items so if the item array is very long I dont have problems showing all the values included on the arrays.

This is what I want to have. Static titles (Id, Pieza, etc), and the content itself inside of the scrollbar. Sorry for the poor Photoshop: enter image description here

And this is my code:

from Tkinter import *
import Image
import ImageTk
import tkFileDialog
import ttk


class Ventanas(Frame):
    def __init__(self,master):
        Frame.__init__(self, master)
        self.master = master
        self.frameOne = Frame(self.master)
        self.frameOne.grid(row=0,column=0)
        self.initial_window()

def initial_window(self):
    self.button1 = Button(self.frameOne, text="go popup window", width=40, command=self.leerjson)
    self.button1.grid(row=1, column=0, padx=(8,8), pady=(10,5))

def leerjson(self):
    piezas = ['time: 39.41597 BT: 3025.5923', 'time: 21.637377 BT: 3025.5923', 'time: 52.185192 BT: 3025.5923', 'time: 57.804752 BT: 3025.5923', 'time: 47.700306 BT: 3025.5923', 'time: 21.1827 BT: 3025.5923', 'time: 35.244156 BT: 3025.5923', 'time: 47.26321 BT: 3025.5923']
    fechaentrada = ['26-02-2014', '26-02-2014', '26-02-2014', '26-02-2014', '26-02-2014', '26-02-2014', '26-02-2014', '21-02-2014']
    fechasalida = ['26-02-2014', '26-02-2014', '26-02-2014', '26-02-2014', '26-02-2014', '26-02-2014', '26-02-2014', '21-02-2014']
    horacomienzo = ['12:00', '12:39', '01:00', '01:52', '02:49', '03:36', '03:57', '12:00']
    horafinal = ['12:39', '01:00', '01:52', '02:49', '03:36', '03:57', '04:32', '12:47']
    ide = [0, 1, 2, 3, 4, 5, 6, 7]

    self.imprimir_carga(piezas, ide, fechaentrada,fechasalida, horacomienzo, horafinal)

def imprimir_carga(self, piezas, ide, fechaentrada,fechasalida, horacomienzo, horafinal):

    window2 = Toplevel(self)

    # TOP WINDOW (w1) - CARGA
    self.idpieza_w1 = Label(window2, text = "Id", width=20, font="bold")
    self.idpieza_w1.grid(row=0, column=0)
    self.pieza_w1 = Label(window2, text = "Pieza", width=20, font="bold")
    self.pieza_w1.grid(row=0, column=1)
    self.fechainiciopromo_w1 = Label(window2, text = "Dia inicio carga", width=20, font="bold")
    self.fechainiciopromo_w1.grid(row=0, column=2)
    self.horainiciopromo_w1 = Label(window2, text = "Hora inicio carga", width=20, font="bold")
    self.horainiciopromo_w1.grid(row=0, column=3)
    self.fechafinalpromo_w1 = Label(window2, text = "Dia fin carga", width=20, font="bold")
    self.fechafinalpromo_w1.grid(row=0, column=4)
    self.horafinalpromo_w1 = Label(window2, text = "Hora final carga", width=20, font="bold")
    self.horafinalpromo_w1.grid(row=0, column=5)

    for i in xrange(len(piezas)):
        self.idtextos_w1 = Label(window2, text=str(ide[i]))
        self.idtextos_w1.grid(row=i+1, column=0)
        self.textos_w1 = Label(window2, text=str(piezas[i]))
        self.textos_w1.grid(row=i+1, column=1)
        self.fechainiciogrid_w1 = Label(window2, text=str(fechaentrada[i]))
        self.fechainiciogrid_w1.grid(row=i+1, column=2)
        self.horainiciogrid_w1 = Label(window2, text=str(horacomienzo[i]))
        self.horainiciogrid_w1.grid(row=i+1, column=3)
        self.fechafinalgrid_w1 = Label(window2, text=str(fechasalida[i]))
        self.fechafinalgrid_w1.grid(row=i+1, column=4)
        self.horafinalgrid_w1 = Label(window2, text=str(horafinal[i]))
        self.horafinalgrid_w1.grid(row=i+1, column=5)

if __name__ == "__main__":
    root = Tk()
    aplicacion = Ventanas(root)
    root.mainloop()

I've read the Scrollbar documentation and it seems this is easy with ListBox and Text, but I'm totally lost if I've to add to a Scrollbar some Labels.

Thanks in advance

Avión
  • 7,963
  • 11
  • 64
  • 105
  • possible duplicate of [Adding a scrollbar to a grid of widgets in Tkinter](http://stackoverflow.com/questions/3085696/adding-a-scrollbar-to-a-grid-of-widgets-in-tkinter) – Bryan Oakley Jan 23 '14 at 11:57

1 Answers1

2

You cannot directly scroll a frame full of widgets. What you will have to do is embed a frame with all of your widgets inside a canvas, then attach a scrollbar to the canvas. This has been asked and answered before:

Adding a scrollbar to a group of widgets in Tkinter

Community
  • 1
  • 1
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685