Nictk 2.2.0
An easy to use pyton GUI
Dialogs.py

A sample of all dialog boxes.

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
26"""The items of this dictionary are tuples with
27 - the name of the function to call
28 - its named parameters
29"""
30DIALOGS = { "Ok - Cancel": (Ntk.askokcancel, {"message":" Do you want to proceed? "}),
31 "Yes - No": (Ntk.askquestion, {"message":" Exit from the application? "}),
32 "Retry - Cancel": (Ntk.askretrycancel, {"message":" Do you want to retry? "}),
33 "Yes - No - Cancel": (Ntk.askyesnocancel, {"message":" Exit from the application? "}),
34 "Error": (Ntk.showerror, {"message":" File not found "}),
35 "Info": (Ntk.showinfo, {"message":" File saved "}),
36 "Warning": (Ntk.showwarning, {"message":" Data could be corrupted "}),
37 "Open File": (Ntk.askopenfilename, {}),
38 "Save as File": (Ntk.asksaveasfilename, {"initialfile":"untitled.py"}),
39 "Open Files": (Ntk.askopenfilenames, {}),
40 "Choose Directory": (Ntk.askdirectory, {}),
41 "Choose color": (Ntk.askcolor, {"color":"#FF0000"})
42 }
43
44
45def open_dialog(event):
46 key = cmbType.get_content()
47 func, arg = DIALOGS[key][0], DIALOGS[key][1]
48 result = func(title=key + " dialog", **arg)
49 diagResult.set("The dialog box returned:\n" + result.__repr__())
50
51
52
53winMain = Ntk.Main(200, 150, 500, 400, "Dialog sample")
54winMain.config_children(ALL, font=("Arial", 16))
55# widgets are aligned with absolute coords
56
57# upper button
58butOpen= Ntk.Button(winMain, CENTER, 20, 320, 60, pad=10,
59 content="Open a dialog box", command=open_dialog)
60butOpen.config(bcolor="#C0F0C0", fcolor="#2020C0")
61
62# combobox for choosing the dialog to open
63cmbType = Ntk.Combobox(winMain, CENTER, PACK, 320, 80, pad=10,
64 items=tuple(DIALOGS.keys()))
65
66diagResult = Ntk.StringVar(value="")
67# lower label for info
68labResult = Ntk.Label(winMain, CENTER, PACK, 400, 160, pad=10, content=diagResult)
69labResult.config(bcolor="#FFFFC0", fcolor="#202060", relief=RIDGE, anchor=CENTER)
70
71Ntk.mainloop()
Definition: constants.py:1