[Tkinter] Listbox only takes one column

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nicolas Favre-Félix

    [Tkinter] Listbox only takes one column

    Hello,

    I have a little problem using Tkinter:
    I'd like to make a interface with 3 labels on the left, facing with 3 Entry
    on the right, a button below Entrys, and a Listbox under all. I could place
    the Labels and Entrys, but the Listbox is just in column 0, and I want it to
    take all the width (column 0 + column 1)

    here is the code:
    ############### ##########
    from Tkinter import *

    root=Tk()

    Label(root, text="Artist :").grid(row =0, column=0)
    Label(root, text="Title :").grid(row =1, column=0)
    Label(root, text="Album :").grid(row =2, column=0)
    Label(root, text="Results :").grid(row =4, column=0)
    results = Listbox(root,se lectmode=SINGLE )
    results.grid(ro w=5, column=0)


    artist = Entry(root)
    title = Entry(root)
    album = Entry(root)

    artist.grid(row =0, column=1)
    title.grid(row= 1, column=1)
    album.grid(row= 2, column=1)
    but= Button(root, text="Find")
    but.grid(row=3, column=1)

    root.mainloop()

    ############### ############### #

    How can I do?

    Thank you.





  • Peter Otten

    #2
    Re: [Tkinter] Listbox only takes one column

    Nicolas Favre-Félix wrote:
    [color=blue]
    > Hello,
    >
    > I have a little problem using Tkinter:
    > I'd like to make a interface with 3 labels on the left, facing with 3
    > Entry on the right, a button below Entrys, and a Listbox under all. I
    > could place the Labels and Entrys, but the Listbox is just in column 0,
    > and I want it to take all the width (column 0 + column 1)
    >
    > here is the code:
    > ############### ##########
    > from Tkinter import *
    >
    > root=Tk()
    >
    > Label(root, text="Artist :").grid(row =0, column=0)
    > Label(root, text="Title :").grid(row =1, column=0)
    > Label(root, text="Album :").grid(row =2, column=0)
    > Label(root, text="Results :").grid(row =4, column=0)
    > results = Listbox(root,se lectmode=SINGLE )[/color]

    results.grid(ro w=5, column=0, columnspan=2)
    [color=blue]
    > artist = Entry(root)
    > title = Entry(root)
    > album = Entry(root)
    >
    > artist.grid(row =0, column=1)
    > title.grid(row= 1, column=1)
    > album.grid(row= 2, column=1)
    > but= Button(root, text="Find")
    > but.grid(row=3, column=1)
    >
    > root.mainloop()
    >
    > ############### ############### #
    >
    > How can I do?
    >
    > Thank you.[/color]

    Just modify results.grid() as shown above. There is also a similar rowspan
    option available, just in case...

    Peter

    Comment

    • Nicolas Favre-Félix

      #3
      Re: [Tkinter] Listbox only takes one column

      Thank you Peter.




      Comment

      Working...