473,324 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Grid View (Table list) in tkinter

4
Is there any data grid sample for tkinter?
Feb 23 '10 #1
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?
Feb 23 '10 #2
AruzV
4
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|___|___|___|___|___|
Feb 24 '10 #3
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
Attached Images
File Type: gif EntryGrid.gif (5.9 KB, 32521 views)
Feb 25 '10 #4
AruzV
4
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.
Feb 25 '10 #5
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.
Expand|Select|Wrap|Line Numbers
  1. import Tkinter
  2. from time import sleep
  3.  
  4. textFont1 = ("Arial", 10, "bold italic")
  5. textFont2 = ("Arial", 16, "bold")
  6. textFont3 = ("Arial", 8, "bold")
  7.  
  8. class LabelWidget(Tkinter.Entry):
  9.     def __init__(self, master, x, y, text):
  10.         self.text = Tkinter.StringVar()
  11.         self.text.set(text)
  12.         Tkinter.Entry.__init__(self, master=master)
  13.         self.config(relief="ridge", font=textFont1,
  14.                     bg="#ffffff000", fg="#000000fff",
  15.                     readonlybackground="#ffffff000",
  16.                     justify='center',width=8,
  17.                     textvariable=self.text,
  18.                     state="readonly")
  19.         self.grid(column=x, row=y)
  20.  
  21. class EntryWidget(Tkinter.Entry):
  22.     def __init__(self, master, x, y):
  23.         Tkinter.Entry.__init__(self, master=master)
  24.         self.value = Tkinter.StringVar()
  25.         self.config(textvariable=self.value, width=8,
  26.                     relief="ridge", font=textFont1,
  27.                     bg="#ddddddddd", fg="#000000000",
  28.                     justify='center')
  29.         self.grid(column=x, row=y)
  30.         self.value.set("")
  31.  
  32. class EntryGrid(Tkinter.Tk):
  33.     ''' Dialog box with Entry widgets arranged in columns and rows.'''
  34.     def __init__(self, colList, rowList, title="Entry Grid"):
  35.         self.cols = colList[:]
  36.         self.colList = colList[:]
  37.         self.colList.insert(0, "")
  38.         self.rowList = rowList
  39.         Tkinter.Tk.__init__(self)
  40.         self.title(title)
  41.  
  42.         self.mainFrame = Tkinter.Frame(self)
  43.         self.mainFrame.config(padx='3.0m', pady='3.0m')
  44.         self.mainFrame.grid()
  45.         self.make_header()
  46.  
  47.         self.gridDict = {}
  48.         for i in range(1, len(self.colList)):
  49.             for j in range(len(self.rowList)):
  50.                 w = EntryWidget(self.mainFrame, i, j+1)
  51.                 self.gridDict[(i-1,j)] = w.value
  52.                 def handler(event, col=i-1, row=j):
  53.                     return self.__entryhandler(col, row)
  54.                 w.bind(sequence="<FocusOut>", func=handler)
  55.         self.mainloop()
  56.  
  57.     def make_header(self):
  58.         self.hdrDict = {}
  59.         for i, label in enumerate(self.colList):
  60.             def handler(event, col=i, row=0, text=label):
  61.                 return self.__headerhandler(col, row, text)
  62.             w = LabelWidget(self.mainFrame, i, 0, label)
  63.             self.hdrDict[(i,0)] = w
  64.             w.bind(sequence="<KeyRelease>", func=handler)
  65.  
  66.         for i, label in enumerate(self.rowList):
  67.             def handler(event, col=0, row=i+1, text=label):
  68.                 return self.__headerhandler(col, row, text)
  69.             w = LabelWidget(self.mainFrame, 0, i+1, label)
  70.             self.hdrDict[(0,i+1)] = w
  71.             w.bind(sequence="<KeyRelease>", func=handler)
  72.  
  73.     def __entryhandler(self, col, row):
  74.         s = self.gridDict[(col,row)].get()
  75.         if s.upper().strip() == "EXIT":
  76.             self.destroy()
  77.         elif s.upper().strip() == "DEMO":
  78.             self.demo()
  79.         elif s.strip():
  80.             print s
  81.  
  82.     def demo(self):
  83.         ''' enter a number into each Entry field '''
  84.         for i in range(len(self.cols)):
  85.             for j in range(len(self.rowList)):
  86.                 sleep(0.25)
  87.                 self.set(i,j,"")
  88.                 self.update_idletasks()
  89.                 sleep(0.1)
  90.                 self.set(i,j,i+1+j)
  91.                 self.update_idletasks()
  92.  
  93.     def __headerhandler(self, col, row, text):
  94.         ''' has no effect when Entry state=readonly '''
  95.         self.hdrDict[(col,row)].text.set(text)
  96.  
  97.     def get(self, x, y):
  98.         return self.gridDict[(x,y)].get()
  99.  
  100.     def set(self, x, y, v):
  101.         self.gridDict[(x,y)].set(v)
  102.         return v
  103.  
  104. if __name__ == "__main__":
  105.     cols = ['A', 'B', 'C', 'D']
  106.     rows = ['1', '2', '3', '4']
  107.     app = EntryGrid(cols, rows)
Feb 25 '10 #6
AruzV
4
Thanks bvdet this is helpful for me.
Feb 28 '10 #7
I have found other examples (mostly inadequate), but none showed how to get data into the script.
Mar 23 '10 #8
muco
1
I desided to use tkinter treeview.
Mar 23 '10 #9
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"?
Mar 23 '10 #10
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.
Mar 24 '10 #11
Would you add a scroll bar to your example?
Mar 26 '10 #12
bvdet
2,851 Expert Mod 2GB
I have never done a scrollbar. I will try adding one when I get some spare time.
Mar 26 '10 #13
Thanks, you can imagine my difficulties.
Mar 27 '10 #14
megumi
1
can you pls help me,i need to put elemeents from a list into the table and cant figure it out.
Dec 30 '18 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
1
by: sonali_aurangabadkar | last post by:
i want to edit whole grid on singel button click
2
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...
2
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...
1
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...
2
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...
1
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...
2
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...
3
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...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
1
isladogs
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...
1
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)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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....
0
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
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.