473,378 Members | 1,391 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,378 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 68675
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, 32541 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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.