Python Forum
Splitting code into several files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Splitting code into several files
#1
Hi Everyone ..
I am trying to split a large .py program into a number of smaller .py files to make maintenance and editing easier ..
I have moved a block of the code into a separate .py file, and when I try running the Main program, I start getting all manner of errors, such as, "tkinter is not defined", frames I defined (in the main) are not defined in the child .py file .. In the Main program I have either "Import Reporting" or "from Reporting import *", and neither statement changes the errors I'm getting ..
I feel I'm missing a basic concept or hint here, but I cannot see it right now ..
If it's a help, I'm working on this inside PyCharm 2021.3 .. Personally, I'm fairly new to Python, but I have a fair bit of programming experience over the years ..
Any suggestions would be useful ..
Thanks in advance ..
thomas
Reply
#2
Have you imported the new file into the old?

In old file: import newfile (drop the .py from import statement)

Please show code.
Reply
#3
Hi there ..
I've included the essentials of the code I'm dealing with .. Where you see <snip>, I've removed tracts of code that doesn't need to be here ..
When I run the code, first error I get is the call to 'setup_reporting_frame', then "name 'tk' is not defined" .. If I define tkinter inside the reporting.py code, next it will complain that 'root' is not defined .. and so on ..
My thinking was that each of the .py modules was compiled, and then the linker would resolve all the naming issues .. Or am I mistaken on that ??
Code follows .. .. ..


*********************************************************
main.py
*********************************************************
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#  Call Schedule Program -- v0.1a
#  Here we go ..
 
import tkinter as tk
import tkinter.font as font
 
from reporting import *             # bring in the stuff from reporting.py
 
 
def center_window_on_screen():
# This centres the window when it is not maximised.
 
    x_cord = int((screen_width / 2) - (width / 2))
    y_cord = int((screen_height / 2) - (height / 2))
    root.geometry(f"{width}x{height}+{x_cord}+{y_cord}")
<<snip!>>

1
2
3
4
5
6
7
8
9
10
11
def change_main_to_report():
# changes from main frame to schedule management frame
 
    reporting_frame.pack(fill='both', expand=1)
    main_frame.forget()
 
 
def change_report_to_main():
# changes from schedule management frame back to main frame
    main_frame.pack(fill='both', expand=1)
    reporting_frame.forget()
<<snip!>>

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
# ---------------< Begin the real work >---------------
# Let's set up the window ...
 
root = tk.Tk()
root.title("The Dreaded Call Schedule v0.1a")
root.configure(bg='lightyellow')
 
width, height = 800, 600
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
center_window_on_screen()
 
# Here, we create frames which we will swap between
main_frame = tk.Canvas(root, width=800, height=600)
file_maint_frame = tk.Canvas(root, width=800, height=600)
phys_maint_frame = tk.Canvas(root, width=800, height=600)
reporting_frame = tk.Canvas(root, width=800, height=600)        # setup reporting frame
 
# Let's create the fonts that we need.
font_large = font.Font(family='Candara',
                       size=24,
                       weight='bold')
font_small = font.Font(family='Candara',
                       size=12)
 
# ---------------< Main Frame >---------------
# The widgets needed for the Main frame.
# First, let's display the logo.
<<snip!>>

1
2
3
4
5
6
7
8
9
10
# ---------------< Reporting Frame >---------------
# The widgets needed for the File Maintenance frame.
 
setup_reporting_frame()         # this code got moved into reporting.py (below)
 
 
# ---------------< Open and Read data files >---------------
 
# Open the files and set those up
#  Physician, Special Characters, Calendar, Main Schedule
<<snip!>>


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
# ---------------< Main Routine >---------------
#
 
main_frame.pack(fill='both', expand=1)
 
root.mainloop()
 
 
 
*********************************************************
reporting.py
*********************************************************
 
 
# ---------------< Reporting Frame >---------------
# The widgets needed for the reporting frame.
 
def setup_reporting_frame():
 
    reporting_frame = tk.Canvas(root, width=800, height=600)
 
    img_logo_report = tk.PhotoImage(file='logo.png')
    lbl_logo_report = tk.Label(reporting_frame, image=img_logo_report)
    lbl_logo_report.place(x=680, y=8)
 
# add a heading.
    lbl_heading_report = tk.Label(reporting_frame,
                            text='Reporting Menu',
                            font=font_large)
    lbl_heading_report.place(x=150, y=100)
 
# button for main availability
    btn_change_report_to_main_avail_rpt = tk.Button(reporting_frame,
                               font=font_small,
                               text='Main Availability',
                               command=change_report_to_main_avail_rpt)
    btn_change_report_to_main_avail_rpt.place(x=150, y=200)
 
# button for surgical avail
    btn_change_report_to_sx_avail_rpt = tk.Button(reporting_frame,
                               font=font_small,
                               text='Surgical Availability',
                               command=change_report_to_sx_avail_rpt)
    btn_change_report_to_sx_avail_rpt.place(x=350, y=200)
 
# button to generate main schedule
    btn_change_report_to_main_sched_rpt = tk.Button(reporting_frame,
                               font=font_small,
                               text='Main Call Schedule',
                               command=change_report_to_main_sched_rpt)
    btn_change_report_to_main_sched_rpt.place(x=150, y=250)
 
# button to generate surgical schedule
    btn_change_report_to_sx_sched_rpt = tk.Button(reporting_frame,
                               font=font_small,
                               text='Surgical Schedule',
                               command=change_report_to_sx_sched_rpt)
    btn_change_report_to_sx_sched_rpt.place(x=350, y=250)
 
# button to swap back to the main frame.
    btn_change_to_main = tk.Button(reporting_frame,
                               font=font_small,
                               text='Exit',
                               command=change_report_to_main)
    btn_change_to_main.place(x=150, y=350)
Larz60+ write Jun-24-2022, 03:00 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.
Reply
#4
I have to go out for several hours, If this post remains unanswered when I return, I'll show you how to proceed.
Reply
#5
Alright .. Below is the code -- all of it .. I fully know it's not the greatest, but I'm learning ..

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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
#  Call Schedule Program -- v0.1a
#  Here we go ..
 
import tkinter as tk
import tkinter.font as font
import csv as csv
import numpy as np
 
from reporting import *
 
 
def center_window_on_screen():
# This centres the window when it is not maximised.
 
    x_cord = int((screen_width / 2) - (width / 2))
    y_cord = int((screen_height / 2) - (height / 2))
    root.geometry(f"{width}x{height}+{x_cord}+{y_cord}")
 
 
def change_main_to_filem():
# changes from main frame to file management frame
 
    file_maint_frame.pack(fill='both', expand=1)
    main_frame.forget()
 
 
def change_filem_to_main():
# changes from file management frame back to main frame
    main_frame.pack(fill='both', expand=1)
    file_maint_frame.forget()
 
 
def change_main_to_schedm():
# changes from main frame to schedule management frame
 
    sched_maint_frame.pack(fill='both', expand=1)
    main_frame.forget()
 
 
def change_schedm_to_main():
# changes from schedule management frame back to main frame
    main_frame.pack(fill='both', expand=1)
    sched_maint_frame.forget()
 
 
def change_main_to_report():
# changes from main frame to schedule management frame
 
    reporting_frame.pack(fill='both', expand=1)
    main_frame.forget()
 
 
def change_report_to_main():
# changes from schedule management frame back to main frame
    main_frame.pack(fill='both', expand=1)
    reporting_frame.forget()
 
 
def change_filem_to_physm():
# changes from file maint frame to physican management frame
 
    phys_maint_frame.pack(fill='both', expand=1)
    file_maint_frame.forget()
 
 
def change_filem_to_charm():
# changes from file maint frame to special character management frame
 
    char_maint_frame.pack(fill='both', expand=1)
    file_maint_frame.forget()
 
 
def change_filem_to_calm():
# changes from file maint frame to calendar management frame
 
    cal_maint_frame.pack(fill='both', expand=1)
    file_maint_frame.forget()
 
 
def change_physm_to_filem():
# changes from physician maint frame back to file maint
    file_maint_frame.pack(fill='both', expand=1)
    phys_maint_frame.forget()
 
 
def change_charm_to_filem():
# changes from character maint frame back to file maint
    file_maint_frame.pack(fill='both', expand=1)
    char_maint_frame.forget()
 
 
def change_calm_to_filem():
# changes from calendar maint frame back to file maint
    file_maint_frame.pack(fill='both', expand=1)
    cal_maint_frame.forget()
 
 
def change_report_to_main_avail_rpt():
# changes from reporting frame to main availability report frame
 
    main_avail_frame.pack(fill='both', expand=1)
    reporting_frame.forget()
 
 
def change_main_avail_rpt_to_report():
# changes from main availability frame back to reporting frame
    reporting_frame.pack(fill='both', expand=1)
    main_avail_frame.forget()
 
 
def change_report_to_sx_avail_rpt():
# changes from reporting frame to surgical availability report frame
 
    sx_avail_frame.pack(fill='both', expand=1)
    reporting_frame.forget()
 
 
def change_sx_avail_rpt_to_report():
# changes from surgical availability frame back to reporting frame
    reporting_frame.pack(fill='both', expand=1)
    sx_avail_frame.forget()
 
 
def change_report_to_main_sched_rpt():
# changes from reporting frame to main schedule reporting frame
 
    main_sched_rpt_frame.pack(fill='both', expand=1)
    reporting_frame.forget()
 
 
def change_main_sched_rpt_to_report():
# changes from schedule management frame back to main frame
    reporting_frame.pack(fill='both', expand=1)
    main_sched_rpt_frame.forget()
 
 
def change_report_to_sx_sched_rpt():
# changes from reporting frame to surgical reporting frame
 
    sx_sched_rpt_frame.pack(fill='both', expand=1)
    reporting_frame.forget()
 
 
def change_sx_sched_rpt_to_report():
# changes from surgical reporting frame back to main frame
    reporting_frame.pack(fill='both', expand=1)
    sx_sched_rpt_frame.forget()
 
 
def save_rtn():
    print("Save and Exit")
    file_save()
    exit()
 
def exit_rtn():
    print("Quit")
    exit()
 
# save all our files...
def file_save():
    temp_file = open("Physician.sch", 'w')
    rows = len(df_phys)
    cols = len(df_phys[0])
    print("Phys : ", rows, cols)
    for i in range(rows):
        for j in range(cols):
            temp_file.write(df_phys[i][j] + "\n")
    temp_file.close()
 
    temp_file = open("Calendar.sch", 'w')
    rows = len(df_cal)
    cols = len(df_cal[0])
    print("Cal  : ", rows, cols)
    for i in range(rows):
        for j in range(cols):
            temp_file.write(df_cal[i][j] + "\n")
    temp_file.close()
 
    temp_file = open("Schedule.sch", 'w')
    rows = len(df_sched)
    cols = len(df_sched[0])
    print("Sched: ", rows, cols)
    for i in range(rows):
        for j in range(cols):
            temp_file.write(df_sched[i][j] + "\n")
    temp_file.close()
 
 
# ---------------< Begin the real work >---------------
 
# Let's set up the window ...
 
root = tk.Tk()
root.title("The Dreaded Call Schedule v0.1a")
root.configure(bg='lightyellow')
# Set the icon used for your program
# root.PhotoImage(file='info.png'))
 
width, height = 800, 600
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
center_window_on_screen()
 
# Here, we create frames which we will swap between
# main_frame = tk.Frame(root)
main_frame = tk.Canvas(root, width=800, height=600)
file_maint_frame = tk.Canvas(root, width=800, height=600)
phys_maint_frame = tk.Canvas(root, width=800, height=600)
char_maint_frame = tk.Canvas(root, width=800, height=600)
cal_maint_frame = tk.Canvas(root, width=800, height=600)
sched_maint_frame = tk.Canvas(root, width=800, height=600)
reporting_frame = tk.Canvas(root, width=800, height=600)
main_avail_frame = tk.Canvas(root, width=800, height=600)
sx_avail_frame = tk.Canvas(root, width=800, height=600)
main_sched_rpt_frame = tk.Canvas(root, width=800, height=600)
sx_sched_rpt_frame = tk.Canvas(root, width=800, height=600)
 
# Let's create the fonts that we need.
font_large = font.Font(family='Candara',
                       size=24,
                       weight='bold')
font_small = font.Font(family='Candara',
                       size=12)
 
# ---------------< Main Frame >---------------
# The widgets needed for the Main frame.
# First, let's display the logo.
 
img_logo_main = tk.PhotoImage(file='logo.png')
lbl_logo_main_frame = tk.Label(main_frame,
                               image=img_logo_main)
lbl_logo_main_frame.place(x=680, y=8)
 
# Next, comes the heading for this frame.
lbl_heading_main_frame = tk.Label(main_frame,
                            text='Welcome to the Call Schedule',
                            font=font_large)
lbl_heading_main_frame.place(x=200, y=100)
 
btn_change_to_work = tk.Button(main_frame,
                               text='File Maintenance',
                               font=font_small,
                               command=change_main_to_filem)
btn_change_to_work.place(x=250, y=200)
 
btn_change_to_sched = tk.Button(main_frame,
                               text='Schedule Work',
                               font=font_small,
                               command=change_main_to_schedm)
btn_change_to_sched.place(x=400, y=200)
 
btn_change_to_report = tk.Button(main_frame,
                               text='Produce Reports',
                               font=font_small,
                               command=change_main_to_report)
btn_change_to_report.place(x=250, y=250)
 
btn_change_to_stuff = tk.Button(main_frame,
                               text='?? future ??',
                               font=font_small,
                               command=change_main_to_schedm)
btn_change_to_stuff.place(x=400, y=250)
 
btn_save_work = tk.Button(main_frame,
                          font=font_small,
                          text='Save and Exit',
                          command=save_rtn)
btn_save_work.place(x=250, y=350)
 
btn_exit_work = tk.Button(main_frame,
                          font=font_small,
                          text='Quit - no Save',
                          command=exit_rtn)
btn_exit_work.place(x=400, y=350)
 
main_frame.create_line(700, 200, 750, 400, width=3, fill='orange')
 
# ---------------< File Maintenance Frame >---------------
# The widgets needed for the File Maintenance frame.
 
# First the image gets added.
img_logo_filem = tk.PhotoImage(file='logo.png')
lbl_logo_file_maint = tk.Label(file_maint_frame,
                         image=img_logo_filem)
lbl_logo_file_maint.place(x=680, y=8)
 
# Next, we'll add a heading.
lbl_heading_file_maint = tk.Label(file_maint_frame,
                            text='File Maintenance',
                            font=font_large)
lbl_heading_file_maint.place(x=150, y=100)
 
# We need the button for Physician Maintenance
btn_change_to_phys_maint = tk.Button(file_maint_frame,
                               font=font_small,
                               text='Physician Maintenance',
                               command=change_filem_to_physm)
btn_change_to_phys_maint.place(x=150, y=200)
 
# We need the button for Special Character Maintenance
btn_change_to_char_maint = tk.Button(file_maint_frame,
                               font=font_small,
                               text='Character Maintenance',
                               command=change_filem_to_charm)
btn_change_to_char_maint.place(x=350, y=200)
 
# We need the button for Calender Maintenance
btn_change_to_cal_maint = tk.Button(file_maint_frame,
                               font=font_small,
                               text='Calender Maintenance',
                               command=change_filem_to_calm)
btn_change_to_cal_maint.place(x=150, y=250)
 
# We need the button to swap back to the main frame.
btn_change_to_main = tk.Button(file_maint_frame,
                               font=font_small,
                               text='Exit',
                               command=change_filem_to_main)
btn_change_to_main.place(x=150, y=300)
 
file_maint_frame.create_line(750, 300, 700, 400, width=3, fill='purple')
 
# ---------------< reporting frame >---------------
 
setup_reporting_frame()
 
## import Reporting
## from Reporting import *
 
# ---------------< Open and Read data files >---------------
 
# Open the files and set those up
#  Physician, Special Characters, Calendar, Main Schedule
 
# ---------------< Physician File >---------------
 
#Counts the number of lines in the File
temp_file = open("physician.sch", 'r')
count = 0
for x in temp_file:
    count = count + 1
temp_file.close()
 
#Calculating number of rows (Total lines / columns)
rows = int(count / 11)
 
#Initializing Lists
df_phys = []
temp_list = []
 
#The actual code
temp_file = open("physician.sch", 'r')
for i in range(rows):
    for j in range(11):
        x = temp_file.readline()
        temp_list = temp_list + x.splitlines()
    print(temp_list)
    df_phys.append(temp_list)
    temp_list = []
 
print(df_phys)
temp_file.close()
 
# ---------------< Calendar File >---------------
 
#Counts the number of lines in the File
temp_file = open("calendar.sch", 'r')
count = 0
for x in temp_file:
    count = count + 1
temp_file.close()
 
#Calculating number of rows (Total lines / columns)
rows = int(count / 3)
 
#Initializing Lists
df_cal = []
temp_list = []
 
#The actual code
temp_file = open("calendar.sch", 'r')
for i in range(rows):
    for j in range(3):
        x = temp_file.readline()
        temp_list = temp_list + x.splitlines()
    print(temp_list)
    df_cal.append(temp_list)
    temp_list = []
 
print(df_cal)
temp_file.close()
 
 
# ---------------< Schedule File >---------------
 
#Counts the number of lines in the File
temp_file = open("schedule.sch", 'r')
count = 0
for x in temp_file:
    count = count + 1
temp_file.close()
 
#Calculating number of rows (Total lines / columns)
rows = int(count / 15)
 
#Initializing Lists
df_sched = []
temp_list = []
 
#The actual code
temp_file = open("schedule.sch",'r')
for i in range(rows):
    for j in range(15):
        x = temp_file.readline()
        temp_list = temp_list + x.splitlines()
    print(temp_list)
    df_sched.append(temp_list)
    temp_list = []
 
print(df_sched)
temp_file.close()
 
# ---------------< Physician Maintenance Frame >---------------
# The widgets needed for the File Maintenance frame.
 
# First the image gets added.
img_logo_phys = tk.PhotoImage(file='info.png')
lbl_logo_phys_maint = tk.Label(phys_maint_frame,
                         image=img_logo_phys)
lbl_logo_phys_maint.place(x=680, y=8)
 
# Next, we'll add a heading.
lbl_heading_phys_maint = tk.Label(phys_maint_frame,
                            text='Physician Maintenance',
                            font=font_large)
lbl_heading_phys_maint.place(x=150, y=100)
 
# We need the button to swap back to the main frame.
btn_change_to_filem = tk.Button(phys_maint_frame,
                               font=font_small,
                               text='Exit',
                               command=change_physm_to_filem)
btn_change_to_filem.place(x=150, y=300)
 
phys_maint_frame.create_line(750, 300, 700, 400, width=3, fill='green')
 
 
# ---------------< Calendar Maintenance Frame >---------------
# The widgets needed for the File Maintenance frame.
 
# First the image gets added.
img_logo_cal = tk.PhotoImage(file='info.png')
lbl_logo_cal_maint = tk.Label(cal_maint_frame,
                         image=img_logo_cal)
lbl_logo_cal_maint.place(x=680, y=8)
 
# Next, we'll add a heading.
lbl_heading_cal_maint = tk.Label(cal_maint_frame,
                            text='Calendar Maintenance',
                            font=font_large)
lbl_heading_cal_maint.place(x=150, y=100)
 
# We need the button to swap back to the main frame.
btn_change_to_filem = tk.Button(cal_maint_frame,
                               font=font_small,
                               text='Exit',
                               command=change_calm_to_filem)
btn_change_to_filem.place(x=150, y=300)
 
cal_maint_frame.create_line(750, 300, 700, 400, width=3, fill='gold')
 
# ---------------< Schedule Maintenance Frame >---------------
# The widgets needed for the Schedule Maintenance frame.
 
# First the image gets added.
img_logo_char = tk.PhotoImage(file='info.png')
lbl_logo_char_maint = tk.Label(sched_maint_frame,
                         image=img_logo_char)
lbl_logo_char_maint.place(x=680, y=8)
 
# Next, we'll add a heading.
lbl_heading_char_maint = tk.Label(sched_maint_frame,
                            text='Main Schedule Maintenance',
                            font=font_large)
lbl_heading_char_maint.place(x=150, y=100)
 
# We need the button to swap back to the main frame.
btn_change_to_filem = tk.Button(sched_maint_frame,
                               font=font_small,
                               text='Exit',
                               command=change_schedm_to_main)
btn_change_to_filem.place(x=150, y=300)
 
char_maint_frame.create_line(750, 300, 700, 400, width=3, fill='light green')
 
# ---------------< Main Routine >---------------
# Only the quiz frame needs to be shown
# when the program starts.  The work frame
# will only appear when the Change button
# is clicked.
main_frame.pack(fill='both', expand=1)
 
root.mainloop()
And reporting.py

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
# ---------------< Reporting Frame >---------------
# The widgets needed for the File Maintenance frame.
 
def setup_reporting_frame():
 
## main_frame = tk.Canvas(root, width=800, height=600)
    reporting_frame = tk.Canvas(root, width=800, height=600)
 
    img_logo_report = tk.PhotoImage(file='logo.png')
    lbl_logo_report = tk.Label(reporting_frame, image=img_logo_report)
    lbl_logo_report.place(x=680, y=8)
 
# Next, we'll add a heading.
    lbl_heading_report = tk.Label(reporting_frame,
                            text='Reporting Menu',
                            font=font_large)
    lbl_heading_report.place(x=150, y=100)
 
# We need the button for main availability
    btn_change_report_to_main_avail_rpt = tk.Button(reporting_frame,
                               font=font_small,
                               text='Main Availability',
                               command=change_report_to_main_avail_rpt)
    btn_change_report_to_main_avail_rpt.place(x=150, y=200)
 
# We need the button for surgical avail
    btn_change_report_to_sx_avail_rpt = tk.Button(reporting_frame,
                               font=font_small,
                               text='Surgical Availability',
                               command=change_report_to_sx_avail_rpt)
    btn_change_report_to_sx_avail_rpt.place(x=350, y=200)
 
# We need the button to generate main schedule
    btn_change_report_to_main_sched_rpt = tk.Button(reporting_frame,
                               font=font_small,
                               text='Main Call Schedule',
                               command=change_report_to_main_sched_rpt)
    btn_change_report_to_main_sched_rpt.place(x=150, y=250)
 
# We need the button to generate surgical schedule
    btn_change_report_to_sx_sched_rpt = tk.Button(reporting_frame,
                               font=font_small,
                               text='Surgical Schedule',
                               command=change_report_to_sx_sched_rpt)
    btn_change_report_to_sx_sched_rpt.place(x=350, y=250)
 
# We need the button to swap back to the main frame.
    btn_change_to_main = tk.Button(reporting_frame,
                               font=font_small,
                               text='Exit',
                               command=change_report_to_main)
    btn_change_to_main.place(x=150, y=350)
 
    reporting_frame.create_line(750, 300, 700, 400, width=3, fill='aqua')
Error message that comes out ..

Error:
C:\Users\Thomas\PycharmProjects\Sched_v01a\venv\Scripts\python.exe C:/Users/Thomas/PycharmProjects/Sched_v01a/main.py Traceback (most recent call last): File "C:\Users\Thomas\PycharmProjects\Sched_v01a\main.py", line 432, in <module> setup_reporting_frame() File "C:\Users\Thomas\PycharmProjects\Sched_v01a\reporting.py", line 15, in setup_reporting_frame reporting_frame = tk.Canvas(root, width=800, height=600) NameError: name 'tk' is not defined Process finished with exit code 1
As I mentioned in my earlier post, if I try defining tkinter inside of reporting.py, then the error moves to 'root' not being defined, and so on ..
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  "pythonic" way of splitting up my code? liggisten 4 1,888 Dec-30-2023, 08:23 PM
Last Post: Gribouillis
  splitting file into multiple files by searching for string AlphaInc 2 2,926 Jul-01-2023, 10:35 PM
Last Post: Pedroski55
  Split gps files based on time (text splitting) dervast 0 2,354 Nov-09-2020, 09:19 AM
Last Post: dervast
Question Code golfing: splitting a list Ofnuts 7 7,840 Jan-12-2017, 11:01 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020