使用导入开始tkinter文件的问题
我试图通过使用导入而不是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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题在于进口。尝试:
而不是
I think the problem is in the import. Try:
and than