作为模块从另一个tkinter文件打开tkinter文件

2024-09-30 01:24:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经创建了两个Tkinter GUI文件,我想通过单击按钮打开第二个文件和第一个文件。我做了一个函数,它只导入第二个文件,但它不工作。代码如下:

def receiver_func():

    exec(open('receiver.py').read()) #None of them is working and raising error
    import receiver 

同时,如果我单独打开这两个文件,它们会运行良好且平滑

以下是错误日志:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\PAKLAP.pk\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "D:/Programming Projects/Investors Foundation/main.py", line 16, in receiver_func
    exec(open('receiver.py').read())
  File "<string>", line 26, in <module>
  File "C:\Users\PAKLAP.pk\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 2766, in __init__
    Widget.__init__(self, master, 'label', cnf, kw)
  File "C:\Users\PAKLAP.pk\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 2299, in __init__
    (widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage3" doesn't exist

Tags: 文件inpyselfinittkinterlocalline

热门问题