I decided to split my program into several files. One of them is gui.py. It contains a function that builds a menu:
def mainWinMenu(root, heads): menuBar = Menu(root) menuFile = Menu(menuBar, tearoff=0) menuAbout = Menu(menuBar, tearoff=0) menuBar.add_cascade(menu=menuFile, label="Файл") menuBar.add_cascade(menu=menuAbout, label="Справка") ... return menuBar
And there is a main file. Here is his excerpt:
from tkinter import * from tkinter.ttk import * from tkinter.messagebox import * from socket import socket, AF_INET, SOCK_STREAM from multiprocessing import Process, Pipe from queries import * from gui import * import pickle import sqlite3 import datetime as dt import os, sys ... root = Tk() root.title("Клиент системы управления задачами") upMenu = mainWinMenu(root, headsru) table = taskTable(root, headsru, result) root.config(menu=upMenu) root.mainloop()
When you run the main file, an error occurs:
Traceback (most recent call last): File "D: \ GDrive \ python \ tasker \ taskerClient \ tasker_lite.py", line 27, in upMenu = mainWinMenu (root, headsru) File "D: \ GDrive \ python \ tasker \ taskerClient \ gui.py ", line 5, in mainWinMenu menuBar = Menu (root) NameError: name 'Menu' is not defined
When it was all in one file, there was no problem. The function starts to operate in the module itself, and not basically. How can I fix this?
Menu
togui.py
- gil9red