'Problem starting tkinter files using import

I'm trying to make my code smaller by using import instead of os.startfile() to open my other .pyw code. I'm having some problems with starting one of the files.

Here is my code:

import os, subprocess, sys
from tkinter import messagebox, Tk, Label, Entry, Button

import home


def start():
     home.start()


root = Tk()


Button(root, text="Go", command=start).pack()

root.mainloop()

(Where Home is the tkinter file I'm trying to start)

And this is the error message:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Pdann.DESKTOP-8GHUG6R\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
    return self.func(*args)
  File "F:\PYOS\login.pyw", line 21, in Ok
    home.start()
  File "F:\PYOS\home.pyw", line 81, in start
    main_btn = Button(root, image= main_icon, command= more_apps, borderwidth= 7)
  File "C:\Users\Pdann.DESKTOP-8GHUG6R\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 2679, in __init__
    Widget.__init__(self, master, 'button', cnf, kw)
  File "C:\Users\Pdann.DESKTOP-8GHUG6R\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 2601, in __init__
    self.tk.call(
_tkinter.TclError: image "pyimage1" doesn't exist

In the file I'm opening I have the start() function around the Tkinter code. I've done this with plenty of other Tkinter gui (pyw) files, but this is the one that doesn't work.

To make things clear, I am trying to start another file of mine with import home, then home.start() which is the function to start the whole thing.



Solution 1:[1]

I think the problem is in the import. Try:

import tkinter as tk

and than

tk.TK()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SimoX