-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWeigh_Station2_dev.py.bak
278 lines (194 loc) · 6.88 KB
/
Weigh_Station2_dev.py.bak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
import tkinter as tk
import serial,time
from tkinter.ttk import Label
from tkinter.messagebox import showinfo
import datetime
import sys
import random
#SERIALPORT = "/dev/ttyUSB0" #Real Sparfun Open Scale
SERIALPORT = "/dev/ttyACM0" #Dummy Sparfun Open Scale on Arduino
BAUDRATE = 9600
#ser = serial.Serial(SERIALPORT, BAUDRATE, timeout =1)
root = tk.Tk()
root.geometry('1000x500')
root.resizable(True, True)
root.title('Troop 30 Food Drive Weigh Station')
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=1)
root.columnconfigure(2, weight=1)
root.rowconfigure(0, weight=1)
root.rowconfigure(1, weight=1)
root.rowconfigure(2, weight=1)
root.rowconfigure(3, weight=1)
root.rowconfigure(4, weight=1)
root.rowconfigure(5, weight=1)
scout = tk.StringVar(root)
weight_to_display = tk.StringVar(root)
ScoutType = tk.StringVar(root)
ScoutType.set("Scout")
Bigtotal = tk.StringVar(root)
Bigtotal.set("0")
#def get_serial(StringToSend):
# print("StringToSend = "+StringToSend)
# weight_string = ""
# weight = 00.0
# miliseconds = 0
# Data_Ready = 0
#
# ser.reset_input_buffer()
# ser.reset_output_buffer()
#
# #ser.write(bytearray("W",'ascii'))
# ser.write(StringToSend.encode('utf-8'))
#
# #time.sleep(.1)
# while (Data_Ready == 0):
# Data_Ready = ser.inWaiting()
# pass
#
# input_string =""
#
# input_string = ser.readline().decode('utf-8')
# print (input_string)
#
# try:
# split_input_string = input_string.split(",")
# print("weight splitting")
# print (split_input_string[0])
# print (split_input_string[1])
# weight_string = split_input_string[0]
# weight_string = weight_string.rstrip()
# weight_string = weight_string.rstrip('lbs')
#
# print("weight_string = "+ weight_string)
# weight = float(weight_string)
#
# print("weight = "+ str(weight))
#
# #miliseconds_string = split_input_string[0].strip()
# #miliseconds = int(miliseconds_string)
#
# print("milliseconds = " + str(miliseconds))
#
# return weight
#
# except:
# print("Not Weight Data")
# print (split_input_string[0])
def write_to_file():
#print("Saving")
ct = 0
bt = 0.0
ScoutName = ""
ScoutTypeDisplay = ""
weight_to_file = ""
print("ScoutName = ")
ScoutName=str(scout.get())
ScoutName = str.title(ScoutName)
print(ScoutName)
print("ScoutType = ")
ScoutTypeDisplay=str(ScoutType.get())
ScoutTypeDisplay=ScoutTypeDisplay.rstrip('\r\n')
print(ScoutTypeDisplay)
print("Donation Weight = ")
weight_to_file = str(weight_to_display.get())
weight_to_file = weight_to_file.rstrip(" lbs.")
print(weight_to_file)
if ScoutName != "":
#hs = open("/home/pi/Desktop/Food_Pantry_Donations.csv","a") #RPI400
hs = open("C:/Users/nicos/Documents/Food_Pantry_Donations.csv","a") #Laptop
ct = datetime.datetime.now()
hs.write(ScoutName)
hs.write(",")
hs.write(ScoutTypeDisplay)
hs.write(",")
hs.write(weight_to_file)
hs.write(",")
hs.write("lbs")
hs.write(",")
bt = float(Bigtotal.get())
bt = round(bt + float(weight_to_file),2)
Bigtotal.set(str(bt))
print("Bigtotal=" + Bigtotal.get())
hs.write(str(bt))
hs.write(",")
hs.write("lbs")
hs.write(",")
hs.write(str(ct))
hs.write(" \n")
hs.close
scout.set(ScoutName)
showinfo(
title='Saved',
message=ScoutName+', thank you for your '+weight_to_file+' lbs. donation!'
)
else:
showinfo(
title='Error not saved',
message='Please Name The '+ ScoutTypeDisplay
)
def Tare_The_Scale():
tare = 0
#Tare = get_serial("x") #gives error with dummy weight
#Tare = get_serial("1")
#Tare = get_serial("x")
btnSaveToFile = tk.Button(
root,text = "Save To File",
font=("Helvetica", 60),command = write_to_file,)
btnSaveToFile.grid(row = 4, column = 2, columnspan = 1, rowspan = 3)
btnTare = tk.Button(
root,text = "Tare",
font=("Helvetica", 20),command = Tare_The_Scale)
btnTare.grid(row = 3, column = 2, columnspan = 1, rowspan = 3)
label1 = tk.Label(
root,
textvariable=(weight_to_display),
font=("Helvetica", 200))
label1.grid(row = 0, column = 0,columnspan = 3,rowspan = 3)
label2 = tk.Label(
root,
textvariable=(Bigtotal),
font=("Helvetica", 60))
label2.grid(row = 3, column = 2,columnspan = 1,rowspan = 1)
label3 = tk.Label(
root,
text=("200 lbs. maxiumum on scale."),
font=("Helvetica", 40))
label3.grid(row = 3, column = 1,columnspan = 1,rowspan = 1)
NameEntry = tk.Entry(root,text = "boy",
textvariable = scout,
font=("Helvetica", 60))
NameEntry.grid(row = 4,column = 1,columnspan=1,rowspan = 3)
r1 = tk.Radiobutton(root, text='Scout', font=("Helvetica", 20), value='Scout', variable=ScoutType)
r1.grid(row = 3, column = 0)
r2 = tk.Radiobutton(root, text='Webelo', font=("Helvetica", 20), value='Webelo', variable=ScoutType)
r2.grid(row = 4, column = 0)
r3 = tk.Radiobutton(root, text='Other', font=("Helvetica", 20), value='Other', variable=ScoutType)
r3.grid(row = 5, column = 0)
def adjust_font_size(event=None):
# Calculate a new font size based on the window width and height
new_font_size = int((root.winfo_width() + root.winfo_height()) // 50) # Adjust this formula as needed
# Set the new font size for all relevant widgets
btnSaveToFile.config(font=("Helvetica", int(new_font_size // 1.5)))
btnTare.config(font=("Helvetica", new_font_size // 2))
label1.config(font=("Helvetica", new_font_size))
label2.config(font=("Helvetica", new_font_size))
label3.config(font=("Helvetica", int(new_font_size // 1.3)))
NameEntry.config(font=("Helvetica", new_font_size))
r1.config(font=("Helvetica", new_font_size // 4))
r2.config(font=("Helvetica", new_font_size // 4))
r3.config(font=("Helvetica", new_font_size // 4))
def my_mainloop():
print("Main Loop")
#weight= get_serial("0") #Real Weight
weight= random.randint(1,110) #Fake weight
data0 = str(weight)
#data0 = data0 + " lbs."
weight_to_display.set(data0 + " lbs.")
print("weight_to_display = "+ data0 )
root.after(1000, my_mainloop)
root.after(1000, my_mainloop)
adjust_font_size(0)
root.bind("<Configure>", adjust_font_size)
root.mainloop(
)