Nictk 2.2.0
An easy to use pyton GUI
RowFrame.py

An example of the use of the Nictk.RowFrame container. It demonstrates the use of the add_row() method for adding to it rows which behave as horizontal frames (i.e. you can pack widget horizontally into them). You can set rows height as absolute, relative (percentual) or "absolute from bottom" values.

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
23
24# TODO: advice that you programmatically don't use constants
25
26
27winMain = Ntk.Main(200, 150, 400, 300, "NtkRowFrame sample")
28rfr1 = Ntk.RowFrame(winMain, 0, 0, "fill", "fill")
29rfr1.config_children(Ntk.Label, relief="solid", bcolor = "blue", fcolor="yellow",
30 anchor="center")
31# In this example we have added all rows, and then selected them with set_active.
32# Is more common to add a row at a time (which sets it as active) and then add
33# widgets to it
34
35# fixed vertical size
36rfr1.add_row(30)
37# percent vertical size
38rfr1.add_row("30%")
39# percent vertical size
40rfr1.add_row("30%")
41# fixed from bottom vertical size
42rfr1.add_row(-10)
43
44# "pack" == PACK and "fill" == FILL
45rfr1.set_active(0)
46lab1 = Ntk.Label(rfr1, "pack", "20%", "30%", "fill", pad=(10, 0), content="A label in row 0")
47lab2 = Ntk.Label(rfr1, "pack", "20%", "50%", "fill", pad=(10, 0), content="This is a fixed height row")
48
49rfr1.set_active(1)
50lab3 = Ntk.Label(rfr1, "pack", "20%", "30%", "60%", pad=(10, 0), content="A label in row 1")
51lab4 = Ntk.Label(rfr1, "pack", "20%", "50%", "60%", pad=(10, 0), content="This is a 30% height row")
52
53rfr1.set_active(2)
54lab5 = Ntk.Label(rfr1, "pack", "20%", "30%", "60%", pad=(10, 0), content="A label in row 2")
55lab6 = Ntk.Label(rfr1, "pack", "20%", "50%", "60%", pad=(10, 0), content="Try to resize the window")
56
57rfr1.set_active(3)
58lab7 = Ntk.Label(rfr1, "pack", 10, "30%", -10, pad=(10, 0), content="A label in row 3")
59lab8 = Ntk.Label(rfr1, "pack", 10, "50%", -10, pad=(10, 0), content="This is a fixed from bottom height row")
60
61Ntk.mainloop()