Skip to content

Commit 67fad7e

Browse files
author
Jijo
committed
Code files added
1 parent 7072e43 commit 67fad7e

File tree

300 files changed

+31466
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

300 files changed

+31466
-0
lines changed

Chapter01/better_hello_tkinter.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""A better Hello World for Tkinter"""
2+
3+
import tkinter as tk
4+
from tkinter import ttk
5+
6+
7+
class HelloView(tk.Frame):
8+
"""A friendly little module"""
9+
10+
def __init__(self, parent, *args, **kwargs):
11+
super().__init__(parent, *args, **kwargs)
12+
13+
self.name = tk.StringVar()
14+
self.hello_string = tk.StringVar()
15+
self.hello_string.set("Hello World")
16+
17+
name_label = ttk.Label(self, text="Name:")
18+
name_entry = ttk.Entry(self, textvariable=self.name)
19+
ch_button = ttk.Button(self, text="Change", command=self.on_change)
20+
hello_label = ttk.Label(self, textvariable=self.hello_string,
21+
font=("TkDefaultFont", 64), wraplength=600)
22+
23+
# Layout form
24+
name_label.grid(row=0, column=0, sticky=tk.W)
25+
name_entry.grid(row=0, column=1, sticky=(tk.W + tk.E))
26+
ch_button.grid(row=0, column=2, sticky=tk.E)
27+
hello_label.grid(row=1, column=0, columnspan=3)
28+
self.columnconfigure(1, weight=1)
29+
30+
def on_change(self):
31+
"""Handle Change button clicks"""
32+
if self.name.get().strip():
33+
self.hello_string.set("Hello " + self.name.get())
34+
else:
35+
self.hello_string.set("Hello World")
36+
37+
38+
class MyApplication(tk.Tk):
39+
"""Hello World Main Application"""
40+
41+
def __init__(self, *args, **kwargs):
42+
super().__init__(*args, **kwargs)
43+
44+
# set the window properties
45+
self.title("Hello Tkinter")
46+
self.geometry("800x600")
47+
self.resizable(width=False, height=False)
48+
49+
# Define the UI
50+
HelloView(self).grid(sticky=(tk.E + tk.W + tk.N + tk.S))
51+
self.columnconfigure(0, weight=1)
52+
53+
54+
if __name__ == '__main__':
55+
app = MyApplication()
56+
app.mainloop()

Chapter01/hello_tkinter.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Hello World application for Tkinter"""
2+
3+
4+
from tkinter import *
5+
from tkinter.ttk
6+
import *
7+
8+
root = Tk()
9+
10+
label = Label(root, text="Hello World")
11+
label.pack()
12+
root.mainloop()

Chapter02/abq_data_entry_spec.rst

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
======================================
2+
ABQ Data Entry Program specification
3+
======================================
4+
5+
6+
Description
7+
-----------
8+
The program is being created to minimize data entry errors for laboratory measurements.
9+
10+
Functionality Required
11+
----------------------
12+
13+
The program must:
14+
15+
* allow all relevant, valid data to be entered, as per the field chart
16+
* append entered data to a CSV file
17+
- The CSV file must have a filename of abq_data_record_CURRENTDATE.csv,
18+
where CURRENTDATE is the date of the checks in ISO format (Year-month-day)
19+
- The CSV file must have all the fields as per the chart
20+
* enforce correct datatypes per field
21+
22+
The program should try, whenever possible, to:
23+
24+
* enforce reasonable limits on data entered
25+
* Auto-fill data
26+
* Suggest likely correct values
27+
* Provide a smooth and efficient workflow
28+
29+
Functionality Not Required
30+
--------------------------
31+
32+
The program does not need to:
33+
34+
* Allow editing of data. This can be done in LibreOffice if necessary.
35+
* Allow deletion of data.
36+
37+
Limitations
38+
-----------
39+
40+
The program must:
41+
42+
* Be efficiently operable by keyboard-only users.
43+
* Be accessible to color blind users.
44+
* Run on Debian Linux.
45+
* Run acceptably on a low-end PC.
46+
47+
Data Dictionary
48+
---------------
49+
+------------+----------+------+------------------+--------------------------+
50+
|Field | Datatype | Units| Range |Descripton |
51+
+============+==========+======+==================+==========================+
52+
|Date |Date | | |Date of record |
53+
+------------+----------+------+------------------+--------------------------+
54+
|Time |Time | |8:00, 12:00, |Time period |
55+
| | | |16:00, or 20:00 | |
56+
+------------+----------+------+------------------+--------------------------+
57+
|Lab |String | | A - E |Lab ID |
58+
+------------+----------+------+------------------+--------------------------+
59+
|Technician |String | | |Technician name |
60+
+------------+----------+------+------------------+--------------------------+
61+
|Plot |Int | | 1 - 20 |Plot ID |
62+
+------------+----------+------+------------------+--------------------------+
63+
|Seed |String | | |Seed sample ID |
64+
|sample | | | | |
65+
+------------+----------+------+------------------+--------------------------+
66+
|Fault |Bool | | |Fault on environmental |
67+
| | | | |sensor |
68+
+------------+----------+------+------------------+--------------------------+
69+
|Light |Decimal |klx | 0 - 100 |Light at plot |
70+
+------------+----------+------+------------------+--------------------------+
71+
|Humidity |Decimal |g/m³ | 0.5 - 52.0 |Abs humidity at plot |
72+
+------------+----------+------+------------------+--------------------------+
73+
|Temperature |Decimal |°C | 4 - 40 |Temperature at plot |
74+
+------------+----------+------+------------------+--------------------------+
75+
|Blossoms |Int | | 0 - 1000 |Number of blossoms in plot|
76+
+------------+----------+------+------------------+--------------------------+
77+
|Fruit |Int | | 0 - 1000 |Number of fruits in plot |
78+
+------------+----------+------+------------------+--------------------------+
79+
|Plants |Int | | 0 - 20 |Number of plants in plot |
80+
+------------+----------+------+------------------+--------------------------+
81+
|Max height |Decimal |cm | 0 - 1000 |Height of tallest plant in|
82+
| | | | |plot |
83+
+------------+----------+------+------------------+--------------------------+
84+
|Min height |Decimal |cm | 0 - 1000 |Height of shortest plant |
85+
| | | | |in plot |
86+
+------------+----------+------+------------------+--------------------------+
87+
|Median |Decimal |cm | 0 - 1000 |Median height of plants in|
88+
|height | | | |plot |
89+
+------------+----------+------+------------------+--------------------------+
90+
|Notes |String | | |Miscellaneous notes |
91+
+------------+----------+------+------------------+--------------------------+

Chapter03/abq_data_entry_spec.rst

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
======================================
2+
ABQ Data Entry Program specification
3+
======================================
4+
5+
6+
Description
7+
-----------
8+
The program is being created to minimize data entry errors for laboratory measurements.
9+
10+
Functionality Required
11+
----------------------
12+
13+
The program must:
14+
15+
* allow all relevant, valid data to be entered, as per the field chart
16+
* append entered data to a CSV file
17+
- The CSV file must have a filename of abq_data_record_CURRENTDATE.csv,
18+
where CURRENTDATE is the date of the checks in ISO format (Year-month-day)
19+
- The CSV file must have all the fields as per the chart
20+
* enforce correct datatypes per field
21+
22+
The program should try, whenever possible, to:
23+
24+
* enforce reasonable limits on data entered
25+
* Auto-fill data
26+
* Suggest likely correct values
27+
* Provide a smooth and efficient workflow
28+
29+
Functionality Not Required
30+
--------------------------
31+
32+
The program does not need to:
33+
34+
* Allow editing of data. This can be done in LibreOffice if necessary.
35+
* Allow deletion of data.
36+
37+
Limitations
38+
-----------
39+
40+
The program must:
41+
42+
* Be efficiently operable by keyboard-only users.
43+
* Be accessible to color blind users.
44+
* Run on Debian Linux.
45+
* Run acceptably on a low-end PC.
46+
47+
Data Dictionary
48+
---------------
49+
+------------+----------+------+------------------+--------------------------+
50+
|Field | Datatype | Units| Range |Descripton |
51+
+============+==========+======+==================+==========================+
52+
|Date |Date | | |Date of record |
53+
+------------+----------+------+------------------+--------------------------+
54+
|Time |Time | |8:00, 12:00, |Time period |
55+
| | | |16:00, or 20:00 | |
56+
+------------+----------+------+------------------+--------------------------+
57+
|Lab |String | | A - E |Lab ID |
58+
+------------+----------+------+------------------+--------------------------+
59+
|Technician |String | | |Technician name |
60+
+------------+----------+------+------------------+--------------------------+
61+
|Plot |Int | | 1 - 20 |Plot ID |
62+
+------------+----------+------+------------------+--------------------------+
63+
|Seed |String | | |Seed sample ID |
64+
|sample | | | | |
65+
+------------+----------+------+------------------+--------------------------+
66+
|Fault |Bool | | |Fault on environmental |
67+
| | | | |sensor |
68+
+------------+----------+------+------------------+--------------------------+
69+
|Light |Decimal |klx | 0 - 100 |Light at plot |
70+
+------------+----------+------+------------------+--------------------------+
71+
|Humidity |Decimal |g/m³ | 0.5 - 52.0 |Abs humidity at plot |
72+
+------------+----------+------+------------------+--------------------------+
73+
|Temperature |Decimal |°C | 4 - 40 |Temperature at plot |
74+
+------------+----------+------+------------------+--------------------------+
75+
|Blossoms |Int | | 0 - 1000 |Number of blossoms in plot|
76+
+------------+----------+------+------------------+--------------------------+
77+
|Fruit |Int | | 0 - 1000 |Number of fruits in plot |
78+
+------------+----------+------+------------------+--------------------------+
79+
|Plants |Int | | 0 - 20 |Number of plants in plot |
80+
+------------+----------+------+------------------+--------------------------+
81+
|Max height |Decimal |cm | 0 - 1000 |Height of tallest plant in|
82+
| | | | |plot |
83+
+------------+----------+------+------------------+--------------------------+
84+
|Min height |Decimal |cm | 0 - 1000 |Height of shortest plant |
85+
| | | | |in plot |
86+
+------------+----------+------+------------------+--------------------------+
87+
|Median |Decimal |cm | 0 - 1000 |Median height of plants in|
88+
|height | | | |plot |
89+
+------------+----------+------+------------------+--------------------------+
90+
|Notes |String | | |Miscellaneous notes |
91+
+------------+----------+------+------------------+--------------------------+

Chapter03/boilerplate.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import tkinter as tk
2+
from tkinter import ttk
3+
4+
# Start coding here
5+
6+
7+
class Application(tk.Tk):
8+
"""Application root window"""
9+
10+
if __name__ == "__main__":
11+
app = Application()
12+
app.mainloop()

Chapter03/button_example.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import tkinter as tk
2+
from tkinter import ttk
3+
4+
parent = tk.Tk()
5+
6+
tvar = tk.StringVar()
7+
def swaptext():
8+
tvar.set('There' if tvar.get() == 'Hi' else 'Hi')
9+
10+
my_button = ttk.Button(parent, textvariable=tvar, command=swaptext)
11+
my_button.pack()
12+
13+
14+
parent.mainloop()

Chapter03/checkbutton_example.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import tkinter as tk
2+
from tkinter import ttk
3+
4+
parent = tk.Tk()
5+
my_boolean_var = tk.BooleanVar()
6+
7+
my_checkbutton = ttk.Checkbutton(
8+
text="Check to make this option True",
9+
variable=my_boolean_var
10+
)
11+
my_checkbutton.pack()
12+
parent.mainloop()

Chapter03/combobox_example.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import tkinter as tk
2+
from tkinter import ttk
3+
4+
parent = tk.Tk()
5+
my_string_var = tk.StringVar()
6+
7+
combobox = ttk.Combobox(
8+
parent,
9+
textvariable=my_string_var,
10+
values=["Option 1", "Option 2", "Option 3"]
11+
)
12+
combobox.pack()
13+
parent.mainloop()

0 commit comments

Comments
 (0)