Nictk 2.2.0
An easy to use pyton GUI
VerScrollFrame.py

An example of the use of the Nictk.VerScrollFrame container.

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_label(event):
27 str_label = "Label " + str(len(vsf1._frame.winfo_children()) + 1)
28 lab = Ntk.Label(vsf1, 10, PACK, -20, 40, pad=5)
29 lab.set_content(str_label)
30
31def del_label(event):
32 # see the VerScroll.Frame.get_intframe() note.
33 if len(vsf1.get_intframe().winfo_children()) > 0:
34 lab = vsf1._frame.winfo_children()[-1]
35 lab.destroy()
36
37
38# main window
39winMain = Ntk.Main(200, 150, 400, 300, "VerScrollFrame sample")
40
41# extern frame
42hfr1 = Ntk.HorFrame(winMain, 0, 0, FILL, FILL)
43# our VerScrollFrame
44vsf1 = Ntk.VerScrollFrame(hfr1, 0, 0, "70%", FILL)
45vsf1.config(relief=SOLID)
46vsf1.config_children(Ntk.Label, relief="solid", bcolor = "blue", fcolor="yellow",
47 anchor=CENTER)
48# vertical frame for buttons
49vfr1 = Ntk.VerFrame(hfr1, PACK, 0, FILL, FILL)
50# buttons
51butAdd = Ntk.Button(vfr1, CENTER, PACK, "80%", 60, pad=(0,10), content="Add label", command=add_label)
52butDel = Ntk.Button(vfr1, CENTER, PACK, "80%", 60, pad=(0,10), content="Delete label", command= del_label)
53
54
55Ntk.mainloop()
Definition: constants.py:1