使用导入开始tkinter文件的问题

发布于 2025-01-21 18:46:39 字数 1333 浏览 0 评论 0原文

我试图通过使用导入而不是OS.startfile()打开我的其他.pyw代码来使我的代码较小。 我在启动其中一个文件时遇到了一些问题。

这是我的代码:(

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()

home是我要启动的tkinter文件)

,这是错误消息:

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

在我打开的文件中,我围绕着tkinter代码的start()函数。 我已经使用了许多其他Tkinter GUI(PYW)文件来完成此操作,但这是不起作用的文件。

为了表明事情,我正在尝试使用导入home,然后home.start()启动我的另一个文件,这是启动整个过程的功能。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

§对你不离不弃 2025-01-28 18:46:39

我认为问题在于进口。尝试:

import tkinter as tk

而不是

tk.TK()

I think the problem is in the import. Try:

import tkinter as tk

and than

tk.TK()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文