Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 84d61fe

Browse files
Added Source codes and updated readme
1 parent 1de4b84 commit 84d61fe

File tree

8 files changed

+281
-1
lines changed

8 files changed

+281
-1
lines changed

‎Images/add-delete.jpg‎

197 KB
Loading[フレーム]

‎README.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
In this tutorial, we'll walk you through the process of creating a **table widget** for displaying tabular data using Tkinter and the ttkbootstrap GUI library. We will also cover how to build a fully functional table and demonstrate how to programmatically add and delete rows. By the end, you'll have a practical solution for managing tabular data in your Python applications with a modern,good looking interactive interface.
44

5-
![How to create a Python tkinter ttkbootstrap table for displaying data](/Images/tkinter-ttkbootstrap-table-creation-tutorial.jpg)
5+
- ![How to create a Python tkinter ttkbootstrap table for displaying data](/Images/tkinter-ttkbootstrap-table-creation-tutorial.jpg)
6+
7+
- ![How to create a Python tkinter ttkbootstrap app for displaying tabular data from databses like sqlite](/Images/add-delete.jpg)
8+
9+
610

711
# Online Tutorial
812

@@ -22,3 +26,4 @@ In this tutorial, we'll walk you through the process of creating a **table widge
2226
- Adding a Row into the tkinter/ttkbootstrap Table
2327
- Deleting a Row in the tkinter/ttkbootstrap table
2428

29+
File renamed without changes.
File renamed without changes.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#How to add a single row into the table
2+
3+
# (c) www.xanthium.in
4+
5+
6+
# Requires ttkbootstrap for running the code
7+
# Install ttkbootstrap using pip
8+
# pip install ttkbootstrap
9+
10+
import ttkbootstrap as ttk
11+
from ttkbootstrap.tableview import Tableview
12+
from ttkbootstrap.constants import *
13+
14+
15+
16+
root = ttk.Window()
17+
root.title(' Tableview Add Row') # Window Name
18+
root.geometry('600x400')
19+
20+
colors = root.style.colors
21+
22+
column_headers = [
23+
{"text": " Name" , "stretch": True, "anchor": "center"},
24+
{"text": " Age" , "stretch": True, "anchor": "center"},
25+
{"text": " Email" , "stretch": True, "anchor": "center"},
26+
27+
]
28+
29+
row_data = [
30+
('John Doe', 28, 'johnqwertyuiohj67895tg.doe@example.com'),
31+
('Jane Smith', 34, 'jane.smith@example.com'),
32+
33+
]
34+
35+
data_table = Tableview(
36+
master = root,
37+
coldata = column_headers,
38+
rowdata = row_data,
39+
pagesize = 3,
40+
autofit = True,
41+
paginated = True,
42+
searchable = True,
43+
bootstyle = SUCCESS,
44+
45+
stripecolor = (colors.light, None),
46+
)
47+
48+
49+
50+
51+
# add a single row
52+
new_row_data = ('New John Doe',280, 'New.doe@example.com') # has to be a tuple ,not a list
53+
54+
data_table.insert_row(index = 0,values = new_row_data) #insert data to the first row row 0
55+
#data_table.insert_row(index = 'end',values = new_row_data) #insert data to the last row ,index = 'end'
56+
57+
data_table.load_table_data() # call Tableview.load_table_data() to update the current view.
58+
59+
60+
data_table.pack(fill = BOTH, expand = YES, padx = 15, pady = 15)
61+
62+
root.mainloop()
63+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#add Multiple rows into the table
2+
3+
# (c) www.xanthium.in
4+
5+
6+
# Requires ttkbootstrap for running the code
7+
# Install ttkbootstrap using pip
8+
# pip install ttkbootstrap
9+
10+
import ttkbootstrap as ttk
11+
from ttkbootstrap.tableview import Tableview
12+
from ttkbootstrap.constants import *
13+
14+
15+
16+
root = ttk.Window()
17+
root.title(' Tableview Add Multiple Rows') # Window Name
18+
root.geometry('600x400')
19+
20+
colors = root.style.colors
21+
22+
column_headers = [
23+
{"text": " Name" , "stretch": True, "anchor": "center"},
24+
{"text": " Age" , "stretch": True, "anchor": "center"},
25+
{"text": " Email" , "stretch": True, "anchor": "center"},
26+
27+
]
28+
29+
row_data = [
30+
('John Doe', 28, 'johnqwertyuiohj67895tg.doe@example.com'),
31+
('Jane Smith', 34, 'jane.smith@example.com'),
32+
33+
]
34+
35+
data_table = Tableview(
36+
master = root,
37+
coldata = column_headers,
38+
rowdata = row_data,
39+
pagesize = 10,
40+
autofit = True,
41+
paginated = True,
42+
searchable = True,
43+
bootstyle = SUCCESS,
44+
45+
stripecolor = (colors.light, None),
46+
)
47+
48+
49+
50+
51+
# add a Multiple rows
52+
new_row_data = [('New John Doe 1 ',280, 'New.doe_1@example.com'),
53+
('New John Doe 2 ',380, 'New.doe_2@example.com'),
54+
('New John Doe 3 ',480, 'New.doe_3@example.com'),
55+
('New John Doe 4 ',580, 'New.doe_4@example.com'),
56+
57+
]# has a list
58+
59+
data_table.insert_rows(index = 0,rowdata = new_row_data) #insert data to the first row row 0
60+
#data_table.insert_rows(index = 'end',rowdata = new_row_data) #insert data to the last row ,index = 'end'
61+
62+
data_table.load_table_data() # call Tableview.load_table_data() to update the current view.
63+
64+
65+
data_table.pack(fill = BOTH, expand = YES, padx = 15, pady = 15)
66+
67+
root.mainloop()
68+
69+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#Adding and Deleting Records from a Table
2+
# (c) www.xanthium.in
3+
4+
5+
# Requires ttkbootstrap for running the code
6+
# Install ttkbootstrap using pip
7+
# pip install ttkbootstrap
8+
import ttkbootstrap as ttk
9+
from ttkbootstrap.tableview import Tableview
10+
from ttkbootstrap.constants import *
11+
12+
def Add_Record_Button_Handler():
13+
# add a single row
14+
new_row_data = ('New John Doe',280, 'New.doe@example.com') # has to be a tuple ,not a list
15+
data_table.insert_row(index = 0,values = new_row_data) #insert data to the first row row 0
16+
data_table.load_table_data() # call Tableview.load_table_data() to update the current view.
17+
18+
19+
def Del_Record_Button_Handler():
20+
data_table.delete_row(index = 0) #Delete the first row
21+
22+
23+
root = ttk.Window()
24+
root.title(' Tableview Add Delete Rows') # Window Name
25+
root.geometry('800x520')
26+
27+
colors = root.style.colors
28+
29+
column_headers = [
30+
{"text": " Name" , "stretch": True, "anchor": "center"},
31+
{"text": " Age" , "stretch": True, "anchor": "center"},
32+
{"text": " Email" , "stretch": True, "anchor": "center"},
33+
34+
]
35+
36+
row_data = [
37+
('John Doe' , 28, 'johnqwertyuiohj67895tg.doe@example.com'),
38+
('Jane Smith' , 34, 'jane.smith@example.com' ),
39+
('Sarah Davis' , 29, 'sarah.davis@example.com' ),
40+
('David Wilson', 33, 'david.wilson@example.com' ),
41+
('Linda Moore' , 38, 'linda.moore@example.com' ),
42+
('James Taylor', 25, 'james.taylor@example.com' ),
43+
('Rachel Clark', 36, 'rachel.clark@example.com' ),
44+
45+
]
46+
47+
Add_Record_Button = ttk.Button(text = 'Add a Row ' ,command = Add_Record_Button_Handler, bootstyle = PRIMARY)
48+
Delete_Record_Button = ttk.Button(text = 'Delete a Row ',command = Del_Record_Button_Handler, bootstyle = DANGER)
49+
50+
data_table = Tableview(
51+
master = root,
52+
coldata = column_headers,
53+
rowdata = row_data,
54+
pagesize = 10,
55+
height = 10,
56+
autofit = True,
57+
paginated = True,
58+
searchable = True,
59+
bootstyle = SUCCESS,
60+
61+
stripecolor = (colors.light, None),
62+
)
63+
64+
65+
66+
data_table.pack(fill = BOTH, expand = NO, padx = 15, pady = 15)
67+
68+
Add_Record_Button.pack(pady =10)
69+
Delete_Record_Button.pack(pady =10)
70+
71+
72+
root.mainloop()
73+
74+
75+
76+

‎Source Codes/_7_Table_Delete_Row.py‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#Delete row inthe table
2+
# (c) www.xanthium.in
3+
4+
5+
# Requires ttkbootstrap for running the code
6+
# Install ttkbootstrap using pip
7+
# pip install ttkbootstrap
8+
9+
import ttkbootstrap as ttk
10+
from ttkbootstrap.tableview import Tableview
11+
from ttkbootstrap.constants import *
12+
13+
14+
15+
root = ttk.Window()
16+
root.title(' Tableview Add Multiple Rows') # Window Name
17+
root.geometry('600x400')
18+
19+
colors = root.style.colors
20+
21+
column_headers = [
22+
{"text": " Name" , "stretch": True, "anchor": "center"},
23+
{"text": " Age" , "stretch": True, "anchor": "center"},
24+
{"text": " Email" , "stretch": True, "anchor": "center"},
25+
26+
]
27+
28+
row_data = [
29+
('John Doe', 28, 'johnqwertyuiohj67895tg.doe@example.com'),
30+
('Jane Smith', 34, 'jane.smith@example.com'),
31+
('Sarah Davis', 29, 'sarah.davis@example.com', ),
32+
('David Wilson', 33, 'david.wilson@example.com', ),
33+
('Linda Moore', 38, 'linda.moore@example.com', ),
34+
('James Taylor', 25, 'james.taylor@example.com', ),
35+
('Rachel Clark', 36, 'rachel.clark@example.com',),
36+
37+
]
38+
39+
data_table = Tableview(
40+
master = root,
41+
coldata = column_headers,
42+
rowdata = row_data,
43+
pagesize = 10,
44+
autofit = True,
45+
paginated = True,
46+
searchable = True,
47+
bootstyle = SUCCESS,
48+
49+
stripecolor = (colors.light, None),
50+
)
51+
52+
53+
54+
55+
56+
data_table.delete_row(index = 0)
57+
58+
59+
60+
61+
62+
data_table.pack(fill = BOTH, expand = YES, padx = 15, pady = 15)
63+
64+
root.mainloop()
65+
66+
67+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /