Python StringGrid

Post here if you need help with creating a Graphical User Interface in Python.

Python StringGrid

Postby eslavko » Sun Dec 29, 2013 8:54 am

Hello...
I lokking for example to show grid of elements on screen.
I mean some frame with grid of elements and scrollbars to slide if grid is bigger than screen. I look over the net and can't find it. Seems that in python has some other name...
eslavko
 
Posts: 25
Joined: Thu Dec 26, 2013 10:23 am

Re: Python StringGrid

Postby eslavko » Sun Dec 29, 2013 9:16 am

to be more clear...
I wan't something like this, but with 2D array of elements. (And to have chance to put graphic in element not only text)

Code: Select all
from Tkinter import *

root = Tk()
scrollbar = Scrollbar(root)
scrollbar.pack( side = RIGHT, fill=Y )

mylist = Listbox(root, yscrollcommand = scrollbar.set )
for line in range(100):
   mylist.insert(END, "This is line number " + str(line))

mylist.pack( side = LEFT, fill = BOTH )
scrollbar.config( command = mylist.yview )


mainloop()
eslavko
 
Posts: 25
Joined: Thu Dec 26, 2013 10:23 am

Re: Python StringGrid

Postby micseydel » Sun Dec 29, 2013 10:14 am

I've moved this post from the general section to the GUI section. I could be wrong, but I think I've done that for you in the past. If you're posting about Tkinter, please post here in the future rather than there.

The general rule is, if there's anything GUI (Tkinter, wxPython, pyQt, etc.) it should go in the GUI section. If it has GUI code but isn't about the GUI part (just a general Python question), then make the post without the GUI code (of course, still, as always, runnable code and such).
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1507
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Python StringGrid

Postby eslavko » Sun Dec 29, 2013 10:27 am

OK.
It's GUI releated so I'm post in wrong section. Will try to not make same mistake more.

About GRID, I found that this function seems to be present in wxPython. Didn't try yet. But still prefer tkinter as it's more portable as I know.
eslavko
 
Posts: 25
Joined: Thu Dec 26, 2013 10:23 am

Re: Python StringGrid

Postby stranac » Sun Dec 29, 2013 1:26 pm

Tkinter also has a grid: http://effbot.org/tkinterbook/grid.htm
eslavko wrote:But still prefer tkinter as it's more portable as I know.

Why do you think that?
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1246
Joined: Thu Feb 07, 2013 3:42 pm

Re: Python StringGrid

Postby eslavko » Sun Dec 29, 2013 1:49 pm

I didn't mean grid manager.
I look for option to have hunderds of element in 2D array (like in excel spreadsheet), with scrollbar to navigate to required one.

about portability, the tkinter is at least installed by default, wx doesn't. I'd like to have program without of thousant of dependencyes.
eslavko
 
Posts: 25
Joined: Thu Dec 26, 2013 10:23 am

Re: Python StringGrid

Postby eslavko » Sun Dec 29, 2013 2:32 pm

I tryed to implement functionality I want, but got into trouble.

When program start all seems ok. If I resize window to make bigger, all seems to be ok too.
But if I resize to have smaller window then sometime status line is missing or only half is visible, and (or) on the right/bottom edge of grid is some whitespace.
Any idea?

Code: Select all
from Tkinter import *

def matrikaConfig(event):
    for child in lader.winfo_children():
        child.destroy()   

    lader.update() 
   
    aa=[]
    for r in range(lader.winfo_height()/50):
        for c in range(lader.winfo_width()/50):
            lader.rowconfigure(r, weight=1)
            lader.columnconfigure(c, weight=1)
            aa.append([])
            aa[-1]=Canvas(lader,bg="white", height=50, width=50,highlightthickness=0)       
            aa[-1].grid(row=r,column=c,sticky=N+S+E+W)
            aa[-1].create_line(0,0,100,0,fill="azure2")
            aa[-1].create_line(0,0,0,100,fill="azure2")
            aa[-1].create_text(0,0, text=str(r)+'/'+str(c), fill="blue", anchor=NW)
   
root = Tk()
root.geometry("700x500")

matrika = Frame(root)
matrika.pack(side=TOP,expand=True,fill=BOTH)
matrika.bind("<Configure>", matrikaConfig)

scrollbarH = Scrollbar(matrika,orient=HORIZONTAL)
scrollbarH.grid(row=1,column=0,sticky=E+W)
scrollbarV = Scrollbar(matrika)
scrollbarV.grid(row=0,column=1,sticky=N+S)

lader=Frame(matrika,bd=2,relief=RAISED)
lader.grid(row=0,column=0,sticky=N+S+E+W)
matrika.rowconfigure(0, weight=1)
matrika.rowconfigure(1, pad=1)
matrika.columnconfigure(0, weight=1)
matrika.columnconfigure(1, pad=1)

StatusText=StringVar()
status = Label(root, anchor=NW, justify=LEFT, textvariable=StatusText,bd=1,relief=SUNKEN)
status.pack(side=BOTTOM,fill=X)
StatusText.set('Status line')

 
root.mainloop()
eslavko
 
Posts: 25
Joined: Thu Dec 26, 2013 10:23 am


Return to GUI

Who is online

Users browsing this forum: No registered users and 1 guest