Python Forum
Function will not load from a module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function will not load from a module
#1
I have a tkinter window, master2.py This window has 14 buttons. Click a button and another window opens. The windows all help me make html for my homework pages, like radio buttons or checkboxes or html tables.

All the functions to make html are in a module guiHTML.py and this works fine, does just what I want.

All the html is saved in a file called "paragraph". When "paragraph" is ready, I click a button in the "master2.py" window called "make the webpage". it asks me a couple of questions, then puts "paragraph" in the html template file. This also works fine.

Because "guiHTML.py" was getting quite long (2674 lines), I thought I would put the function "makeWebpage.py" in another module. I called the module "makeWebpage1.py".

At the top of the master window "master2.py" I have this to import what I need, including my modules "guiHTML" and "makeWebpage1":

import os, sys    
# to import the files we need the paths
path = '/home/pedro/myPython/myModules/'

# append the paths
sys.path.append(path)

import tkinter as tk
from tkinter import *
from functools import partial      
import guiHTML
import makeWebpage1
In the master2 window I have a function:

def openMakewebpage():
    #call the makePage function defined in the makeWebpage1 module
    makeWebpage1.makeWebpage()
and a button:

btn14 = tk.Button(frame1, text='open make webpage', command=openMakewebpage)
btn14.grid(columnspan=2, column=0, row=8, sticky='w', pady=10)
Strangely, the button does not open the window to make the webpage. All other functions, defined in "guiHTML" work fine.

If I put the function "makeWebpage()" in the module guiHTML.py and set:

def openMakewebpage():
    #call the makePage function defined in the guiHTML module
    guiHTML.makeWebpage()
Everything works fine, the function "makeWebpage()" opens normally and does its job!!

My problem is: the exact same function works from 1 module, but not from the other module!

If I try and call the function "makeWebpage()" from the module "makeWebpage1", nothing happens.

When I call the function "makeWebpage()" from the module "guiHTML" everything works fine.

Stranger still: for testing purposes I define a function "myApp()" for any function I make. I paste the function into Idle and enter myApp(). If there is a problem, I can see where it is and fix it.

When I do that with my master window "master2.py" the function "makeWebpage()" opens fine from the module "makeWebpage1" and works fine!!

I cannot explain this.

Do any of you have a clue why my function "makeWebpage()" works from the module "guiHTML" but not from the module "makeWebpage1"?

Or why both work when I do this in Idle??

Ever had a similar problem??
Reply
#2
Is the function called at all? Add a print statement in the function. If called, there must be some sort of missing resource problem. If not called I would look for typos.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  from module import function krishanu21 4 2,644 Apr-22-2020, 10:58 AM
Last Post: buran
  Running function from parent module which has a loop in it. ta2909i 1 2,678 Nov-18-2019, 07:04 PM
Last Post: Gribouillis
  importin function vs. import module hikerguy62 2 2,070 Jul-28-2019, 03:13 PM
Last Post: ndc85430
  function NOT imported from a module Skaperen 10 6,032 Aug-31-2018, 07:30 AM
Last Post: Gribouillis
  python import sybpydb error: DLL load failed: The specified module could not be found andieDu 3 7,649 Apr-04-2018, 06:58 AM
Last Post: Larz60+
  Could not load module Bani 3 4,247 May-24-2017, 11:26 AM
Last Post: buran
  Python help with module function return dictionary tebirkes 14 15,795 Oct-15-2016, 11:45 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