Is there any data grid sample for tkinter?
14 68616 bvdet 2,851
Expert Mod 2GB
AruzV,
Can you be more specific? Are you looking for an example of a Tkinter widget using the grid geometry manager?
I need a sample table viewer in tkinter like excell or any database viewer. It must have Columns and rows and headers. Like this.
_|_A_|_B_|_C_|_D_|_E_|
1|___|___|___|___|___|
2|___|___|___|___|___|
3|___|___|___|___|___|
4|___|___|___|___|___|
5|___|___|___|___|___|
bvdet 2,851
Expert Mod 2GB
Have you tried to code this for yourself? Do you know anything about Tkinter? Is this homework? I can provide code to parametrically build a grid like you describe, but we are not here to provide code to people without some effort on their part. I attached an image of a grid of Tkinter.Entry widgets. The column and row headers are not modifiable. Characters can be entered into the open grids. The fields are bound to '<FocusOut>' (prints field contents if not blank, destroys the top level widget if 'exit' is entered).
BV - Moderator
I am newer in python and tkinter. This is not my homework. I am not a student. I couldn't find any widget. Is there a widget for table view like this:
>>>dview=tkinter.tableview()
>>>dview.pack()
>>>dview.cell[2][3].text="some string"
>>>dview.cell[2][4].image="someimage.png"
>>>dbutton=dview.cell[1][1].button
but I couldnt find in google. There are some samples but they are not enough for me.
bvdet 2,851
Expert Mod 2GB
In that case, I have no problem posting sample code. Type "demo" into one of the cells and tab out to see what happens. - import Tkinter
-
from time import sleep
-
-
textFont1 = ("Arial", 10, "bold italic")
-
textFont2 = ("Arial", 16, "bold")
-
textFont3 = ("Arial", 8, "bold")
-
-
class LabelWidget(Tkinter.Entry):
-
def __init__(self, master, x, y, text):
-
self.text = Tkinter.StringVar()
-
self.text.set(text)
-
Tkinter.Entry.__init__(self, master=master)
-
self.config(relief="ridge", font=textFont1,
-
bg="#ffffff000", fg="#000000fff",
-
readonlybackground="#ffffff000",
-
justify='center',width=8,
-
textvariable=self.text,
-
state="readonly")
-
self.grid(column=x, row=y)
-
-
class EntryWidget(Tkinter.Entry):
-
def __init__(self, master, x, y):
-
Tkinter.Entry.__init__(self, master=master)
-
self.value = Tkinter.StringVar()
-
self.config(textvariable=self.value, width=8,
-
relief="ridge", font=textFont1,
-
bg="#ddddddddd", fg="#000000000",
-
justify='center')
-
self.grid(column=x, row=y)
-
self.value.set("")
-
-
class EntryGrid(Tkinter.Tk):
-
''' Dialog box with Entry widgets arranged in columns and rows.'''
-
def __init__(self, colList, rowList, title="Entry Grid"):
-
self.cols = colList[:]
-
self.colList = colList[:]
-
self.colList.insert(0, "")
-
self.rowList = rowList
-
Tkinter.Tk.__init__(self)
-
self.title(title)
-
-
self.mainFrame = Tkinter.Frame(self)
-
self.mainFrame.config(padx='3.0m', pady='3.0m')
-
self.mainFrame.grid()
-
self.make_header()
-
-
self.gridDict = {}
-
for i in range(1, len(self.colList)):
-
for j in range(len(self.rowList)):
-
w = EntryWidget(self.mainFrame, i, j+1)
-
self.gridDict[(i-1,j)] = w.value
-
def handler(event, col=i-1, row=j):
-
return self.__entryhandler(col, row)
-
w.bind(sequence="<FocusOut>", func=handler)
-
self.mainloop()
-
-
def make_header(self):
-
self.hdrDict = {}
-
for i, label in enumerate(self.colList):
-
def handler(event, col=i, row=0, text=label):
-
return self.__headerhandler(col, row, text)
-
w = LabelWidget(self.mainFrame, i, 0, label)
-
self.hdrDict[(i,0)] = w
-
w.bind(sequence="<KeyRelease>", func=handler)
-
-
for i, label in enumerate(self.rowList):
-
def handler(event, col=0, row=i+1, text=label):
-
return self.__headerhandler(col, row, text)
-
w = LabelWidget(self.mainFrame, 0, i+1, label)
-
self.hdrDict[(0,i+1)] = w
-
w.bind(sequence="<KeyRelease>", func=handler)
-
-
def __entryhandler(self, col, row):
-
s = self.gridDict[(col,row)].get()
-
if s.upper().strip() == "EXIT":
-
self.destroy()
-
elif s.upper().strip() == "DEMO":
-
self.demo()
-
elif s.strip():
-
print s
-
-
def demo(self):
-
''' enter a number into each Entry field '''
-
for i in range(len(self.cols)):
-
for j in range(len(self.rowList)):
-
sleep(0.25)
-
self.set(i,j,"")
-
self.update_idletasks()
-
sleep(0.1)
-
self.set(i,j,i+1+j)
-
self.update_idletasks()
-
-
def __headerhandler(self, col, row, text):
-
''' has no effect when Entry state=readonly '''
-
self.hdrDict[(col,row)].text.set(text)
-
-
def get(self, x, y):
-
return self.gridDict[(x,y)].get()
-
-
def set(self, x, y, v):
-
self.gridDict[(x,y)].set(v)
-
return v
-
-
if __name__ == "__main__":
-
cols = ['A', 'B', 'C', 'D']
-
rows = ['1', '2', '3', '4']
-
app = EntryGrid(cols, rows)
Thanks bvdet this is helpful for me.
I have found other examples (mostly inadequate), but none showed how to get data into the script.
bvdet 2,851
Expert Mod 2GB
I have found other examples (mostly inadequate), but none showed how to get data into the script.
What data are you trying to get into "the script"?
No laughing! I want to write a version of Quicken. I was forced to upgrade to Q2010 from Q2001 when I got Win7 64 bit. Q2010 is so awful that I must do something. I have started using GnuCash which is awkward, but a lot better than Q2010.
Would you add a scroll bar to your example?
bvdet 2,851
Expert Mod 2GB
I have never done a scrollbar. I will try adding one when I get some spare time.
Thanks, you can imagine my difficulties.
can you pls help me,i need to put elemeents from a list into the table and cant figure it out.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Diego |
last post by:
Hi all, I want to show in a grid view a list of Items with the possibility
of modify them, I don't want to show the item code because is just an
autoincremental integer, The Grid View is linked to...
|
by: sonali_aurangabadkar |
last post by:
i want to edit whole grid on singel button click
|
by: probashi |
last post by:
Hi,
Using the SqlDataSource/SelectParameters/ControlParameter one can
easily bind a Grid View with a list box (or any other controls), pretty
cool, but my list box is multi select.
My...
|
by: Umeshnath |
last post by:
Hi,
I have placed a grid view inside Atlas panel. On click of a button event,
data is populated in the grid view, I want to add scroll bar instead of
increasing the size of grid view.
I have...
|
by: usaccess |
last post by:
Hi
I have a sql data source that is pointing to a table which is accessed
through a grid view.
My goal is to have one of the columns in this table be populated as a
drop down list from...
|
by: Valli |
last post by:
Hi,
I am using a gridview to display data from table. In the gridview, there
are 5 columns in which one column contains link name(eg.
http://www.msn.com).
I want to show this link as an...
|
by: Ankit |
last post by:
Hi guys i need to make a table to store a certain data using
Tkinter..I have searched on the group but i have not been able to find
a solution that would work for me..The thing is that i want my...
|
by: shahidrasul |
last post by:
hi
in my project a data grid view in which is show a list of employees which i get from database, i add a even double click on any cell , when i click on any cell, i want to display a form to...
|
by: amitjain123 |
last post by:
Hi All,
I need one solution.
I have list box and grid view on screen. I want to add selected item of list box into grid view as row. Using javascript.
Can we do this?
Is any alternative...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |