Ok, I made a mistake when testing your script. There were errors in the script that you provided as written that I misinterpreted as related to the importation of the module. It turns out that you don’t have to import the main module into the second module where the function is located for the root reference.
Here are the two test scripts whereby you can test the app and verify for yourself.
# abc_1.py
# import tkinter as tk
from tkinter import ttk
# creates entry should be OK
def create_entry(root, row_nr, l_text, l_col, e_size, text_var, pad_x, pad_y):
l_name = ttk.Label(root, text=l_text, justify="left", width=len(l_text)) # create a label first
l_name.grid(row=row_nr, column=l_col, padx=pad_x, pady=pad_y) # define position
e_name = ttk.Entry(root, width=e_size, justify="left", textvariable=text_var) # create the entry
e_name.grid(row=row_nr, column=l_col + 1, padx=pad_x, pady=pad_y) # define position
and finally …
# abc_2.py
import tkinter as tk
from tkinter import ttk
from abc_1 import create_entry
root = tk.Tk()
root.title("Create CA and certs")
root.geometry('500x300') # x, y
# Create Main Frame
main_frame = ttk.Frame(root)
##main_frame.pack(fill=tk.BOTH, expand=1)
create_entry(root, 1, 'My Label Here', 1, 10, 1, 2, 5)
Note that when creating windows with tk
, it is generally advised to stick with one form of widget placement (be it .grid, .pack, etc., but don’t mix and match).
Run the module abc_2.py
. It should work now.
Hope this helps.