Nictk 2.2.0
An easy to use pyton GUI
RowScrollFrame.py

An example of the use of the Nictk.RowScrollFrame container. The file uses the add_row() and del_row() methods) for adding and deleting rows which behave as horizontal frames (i.e. you can pack widget horizontally into them). When the height of the rows stack exceeds the frame height a vertical scrollbar appears on the right.

1# This file is part of Nictk - A simple tkinter wrapper.
2# Copyright (C) 2021-2024 Nicola Cassetta
3# See <https://github.com/ncassetta/Nictk>
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License as published
7# by the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU Lesser General Public License for more details.
14#
15# You should have received a copy of the Lesser GNU General Public License
16# along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18
19# Allows import from parent folder. You can delete this if you install the package
20import _setup
21
22import Nictk as Ntk
23from Nictk.constants import *
24
25
26def add_row(event):
27 rsf1.add_row(40)
28 Ntk.Label(rsf1, PACK, PACK, "40%", FILL, pad=5, content="Row " + str(rsf1._rows[-1].num))
29 Ntk.Label(rsf1, PACK, PACK, "40%", FILL, pad=5, content="Label 2")
30
31def del_row(event):
32 # see the VerScroll.Frame.get_intframe() note.
33 if rsf1.num_rows() > 0:
34 rsf1.del_row(rsf1.num_rows() - 1)
35
36
37# main window
38winMain = Ntk.Main(200, 150, 400, 300, "VerScrollFrame sample")
39
40# extern frame
41hfr1 = Ntk.HorFrame(winMain, 0, 0, FILL, FILL)
42# our VerScrollFrame
43rsf1 = Ntk.RowScrollFrame(hfr1, 0, 0, "70%", FILL)
44rsf1.config(relief=SOLID)
45rsf1.config_children(Ntk.Label, relief="solid", bcolor = "blue", fcolor="yellow",
46 anchor=CENTER)
47# vertical frame for buttons
48vfr1 = Ntk.VerFrame(hfr1, PACK, 0, FILL, FILL)
49# buttons
50butAdd = Ntk.Button(vfr1, CENTER, PACK, "80%", 60, pad=(0,10), content="Add row", command=add_row)
51butDel = Ntk.Button(vfr1, CENTER, PACK, "80%", 60, pad=(0,10), content="Delete row", command= del_row)
52
53
54Ntk.mainloop()
Definition: constants.py:1