Issue
How to get started with creating a similar table using Tkinter?
Solution
Use the Ttk/Tkinter Treeview widget. This provides either a tree-style layout or a listview style columns with headings layout.
As the Treeview
widget is from Tk's themed icon set it will look appropriate on Windows - picking up the current border and column heading styles so that the look should match the current example posted.
Example (that will work in both Python 2 & 3):
try:
from Tkinter import *
from ttk import *
except ImportError: # Python 3
from tkinter import *
from tkinter.ttk import *
class App(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.CreateUI()
self.LoadTable()
self.grid(sticky = (N,S,W,E))
parent.grid_rowconfigure(0, weight = 1)
parent.grid_columnconfigure(0, weight = 1)
def CreateUI(self):
tv = Treeview(self)
tv['columns'] = ('starttime', 'endtime', 'status')
tv.heading("#0", text='Sources', anchor='w')
tv.column("#0", anchor="w")
tv.heading('starttime', text='Start Time')
tv.column('starttime', anchor='center', width=100)
tv.heading('endtime', text='End Time')
tv.column('endtime', anchor='center', width=100)
tv.heading('status', text='Status')
tv.column('status', anchor='center', width=100)
tv.grid(sticky = (N,S,W,E))
self.treeview = tv
self.grid_rowconfigure(0, weight = 1)
self.grid_columnconfigure(0, weight = 1)
def LoadTable(self):
self.treeview.insert('', 'end', text="First", values=('10:00',
'10:10', 'Ok'))
def main():
root = Tk()
App(root)
root.mainloop()
if __name__ == '__main__':
main()
This should yield something like this on Windows:
Answered By - patthoyts
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.